咨询热线:4006-75-4006

售前:9:00-23:30    备案:9:00-18:00    技术:7*24h

python连接mysql提示\"Can\'t connect to local MySQL server through socket...\"的解决方法:

2016-08-20 05:45:26 12954次

在连接mysql数据库函数中指定socket文件,如下: 

#!/usr/bin/python
from MySQLdb import connect
conn = connect(db="pzy", user="root", host="localhost", unix_socket="/storage/db/mysql/mysql.sock")
cur = conn.cursor()
count=cur.execute("show databases")
print 'there has %s dbs' % count
conn.commit()
conn.close()


首页
最新活动
个人中心