sudo apt-get install python-mysqldb
#!/usr/bin/env python #encoding=utf-8 import sys import MySQLdb reload(sys) sys.setdefaultencoding(‘utf-8‘) try: conn=MySQLdb.connect(host=‘localhost‘,user=‘root‘,passwd=‘root‘,db=‘mysql‘,port=3306,charset=‘utf8‘) cur=conn.cursor() count=cur.execute("SELECT * FROM user") print ‘there has %s rows record‘ % count info = cur.fetchall() print info cur.close() conn.commit() conn.close() except MySQLdb.Error,e: print "Mysql Error %d: %s" % (e.args[0], e.args[1])
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-11-13 07:58:04