python 2.7 连接mysql

  • Post author:
  • Post category:mysql


sudo pip  install  MySQL-python

# import xlrd
import MySQLdb.cursors
conn=MySQLdb.connect(host='ip',
                    user='user',
                    passwd='password',
                    db='db name',
                    charset='utf8') 
    cursor = conn.cursor()        
    cursor.execute ("select * from tablename")
    row = cursor.fetchall()
    cursor.close()  
    conn.close()



版权声明:本文为haogeoyes原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。