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])


相关文章:

  • 2021-04-21
  • 2021-08-20
  • 2021-06-11
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-21
  • 2021-08-20
  • 2021-08-12
  • 2021-06-05
相关资源
相似解决方案