用python创建MySQL数据库

编程入门 行业动态 更新时间:2024-10-26 07:40:06
本文介绍了用python创建MySQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想使用以下参数执行文件:./file.py服务器地址arg2 arg3 arg4

I want to execute a file with parameters like this : ./file.py server adress arg2 arg3 arg4

file1.py :

import MySQLdb # Open database connection db = MySQLdb.connect("localhost","testuser","test123","TESTDB" ) # prepare a cursor object using cursor() method cursor = db.cursor() # execute SQL query using execute() method. cursor.execute("SELECT VERSION()") # Fetch a single row using fetchone() method. data = cursor.fetchone() print "Database version : %s " % data # disconnect from server db.close()

推荐答案

使用内置模块 argparse .或optparse(如果您使用的是Python 2.6或更早版本).

Use the built-in module argparse. Or optparse if you're stuck on Python 2.6 or earlier.

更多推荐

用python创建MySQL数据库

本文发布于:2023-10-15 11:59:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1494277.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库   python   MySQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!