Python操作MySQL数据库
首先需要先有Python的MySQL连接模块MySQLdb
在CentOS 5.4下已经默认安装上了,Ubuntu下面没有,需要自己手动安装,下载地址如下:
下载地址:http://sourceforge.net/projects/mysql-python/
一个能覆盖80%使用场景的例子:
import MySQLdb # 建立一个连结 con = MySQLdb.connect(host="127.0.0.1", port=3306, user="root", passwd="123456", db="test") # 生成一个cursor, 用来执行sql语句 cursor = con.cursor() # 执行sql语句 sql = "SELECT * FROM Users" cursor.execute(sql) # Fetch all results from the cursor into a sequence and close the connection # 取得返回的值并关闭连接 results = cursor.fetchall()
相关推荐
迷途风景 2020-07-28
wyqwilliam 2020-06-13
JamesRayMurphy 2020-05-31
usepython 2020-05-28
gululululu 2020-05-28
爱文学更爱编程 2020-05-26
llltaotao 2020-05-19
ericxieforever 2020-05-07
zhongzhiwei 2020-05-08
zjyhll 2020-05-06
bcbeer 2020-04-16
景泽元的编程 2020-04-16
jhshanyu00 2020-04-10
gululululu 2020-03-20
URML 2020-02-22
Yasin 2020-02-13
waiwaiLILI 2020-02-03
wintershii 2020-02-01