yum install MySQL-python
#!/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[0],e.args[1]))python connection.py (‘information_schema‘,) (‘mysql‘,) (‘performance_schema‘,) (‘test‘,) (‘test1‘,)
本文出自 “9527” 博客,请务必保留此出处http://liangey.blog.51cto.com/9097868/1734481
原文:http://liangey.blog.51cto.com/9097868/1734481