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]