请1我的 发表于 2016-1-14 08:52:41

python MySQLdb


1
yum install MySQL-python





1
2
3
4
5
6
7
8
9
10
11
12
#!/usr/bin/python
import MySQLdb
try:
    conn=MySQLdb.connect(host='localhost',user='root',passwd='123456',db='mysql',port=3306)
    cur=conn.cursor()
    cur.execute('show databases;')
    for data in cur.fetchall():
      print data
    cur.close()
    conn.close()
except MySQLdb.Error,e:
    print("mysql Error %d: %s " % (e.args,e.args))






1
2
3
4
5
6
python connection.py
('information_schema',)
('mysql',)
('performance_schema',)
('test',)
('test1',)






页: [1]
查看完整版本: python MySQLdb