MySQL-python连接socket问题
2017-01-23 16:27
459 查看
MySQL-python连接socket问题
Python中使用MySQLdb连接数据库时出现以下错误:Traceback (most recent call last): File "/home/monitor_user/serverMonitor.py", line 206, in <module> ServerList = sqlQuery(getMngConn(), "select b.db_name, a.ip_inside, a.port from machine a inner join dbinfo b on b.machine_id = a.machine_id") File "/home/monitor_user/serverMonitor.py", line 39, in getMngConn return MySQLdb.connect(host='localhost', user='monitor_user', passwd='monitor.user', db='dbmanage') File "build/bdist.linux-x86_64/egg/MySQLdb/__init__.py", line 81, in Connect File "build/bdist.linux-x86_64/egg/MySQLdb/connections.py", line 187, in __init__ _mysql_exceptions.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)")
其原因是我将mysql的sock文件已经调整到/tmp/mysql.sock,所以必须在mysqldb中指定sock的路径(这个还是很不智能的,万一我有很多mysql服务器,而每台服务器的sock路径都有差异呢?)
return MySQLdb.connect(host='localhost', user='user', passwd='user', db='dbname', unix_socket='/tmp/mysql.sock' )
unix_socket参数指定了sock文件的路径
service mysqld status
grep socket /etc/my.cnf | cut -d= -f2
mysql -u root -p
相关文章推荐
- MySQL-python连接socket问题
- python连接mysql时的乱码问题
- 解决python连接mysql,UTF-8乱码问题
- Windows下用Python连接mysql若干问题
- 自学python问题(1)-django连接mysql
- 解决Python2.7 连接MySQL数据库遇到'can't connect to MySQL server on 'localhost'(10061)'问题
- python的sqlaclchemy模块连接mysql数据出现中文乱码问题
- 【python】python连接mysql乱码问题
- (django问题)连接数据库mysql(python-mysql)
- mysql安装之socket连接问题
- 解决python连接mysql报错问题
- Python中Socket的Close方法假关闭Socket连接的问题
- python 连接数据库-设置oracle ,mysql 中文字符问题
- Python连接Mysql&&解决数据库汉字显示乱码问题
- 一键搞定python连接mysql驱动有关问题(windows版本)
- python 以nosql方式连接mysql handlersocket插入操作获得变量值方法
- windows下用Python连接mysql报错问题“MySQLdb in Python: “Can't connect to MySQL server on 'localhost'””
- python 连接mysql 出现问题
- python安装,连接Mysql出现的问题相关总结
- MySQl-python模块,python连接数据库出现的问题