yum install MySQL-python
#!/usr/bin/env 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',)