繁体   English   中英

MySQLPython忽略了我的my.cnf文件。 它从哪里获取信息?

[英]MySQLPython is ignoring my my.cnf file. Where does it get its information?

当我尝试使用MySQLPython(通过SQLAlchemy)时,我收到错误

 File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/MySQL_python-1.2.3c1-py2.6-macosx-10.6-x86_64.egg/MySQLdb/connections.py", line 188, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
sqlalchemy.exc.OperationalError: (OperationalError) (2002, "Can't connect to local MySQL server through socket '/opt/local/var/run/mysql5/mysqld.sock' (2)") None None

但我的机器上没有其他mysql客户端看得很好!

我的my.cnf文件说明:

[client]
port            = 3306
socket          = /tmp/mysql/mysql.sock

[safe_mysqld]
socket          = /tmp/mysql/mysql.sock

[mysqld_safe]
socket          = /tmp/mysql/mysql.sock

[mysqld]
socket          = /tmp/mysql/mysql.sock
port            = 3306

而mysql.sock文件确实位于/ tmp / mysql中

我确认〜/ .my.cnf和/var/lib/mysql/my.cnf没有覆盖它。 mysql5客户端程序等没有连接问题,也没有使用jdbc / mysql连接在同一台机器上安装groovy / grails

thrilllap-2:~ swirsky$ mysql5
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.1.47 Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| test               |
+--------------------+
2 rows in set (0.00 sec)

mysql> 

为什么MySQLdb for python不能解决这个问题呢? 如果不是my.cnf文件,它会在哪里?

您是否尝试将选项read_default_file='~/.my.cnf'到您的connect()调用中,以告诉Python数据库驱动程序读取您的配置文件? 我认为否则它会默认忽略该文件。

默认情况下,MysqlDBlib不读取/etc/my.cnf。 将read_default_group =“client”添加到MySQLdb.connect调用将使其读取客户端部分。

FWIW:我通过将my.cnf中的.sock文件位置更改为MySQLdb想要的位置来修复它(/opt/local/var/run/mysql5/mysqld.sock),但我讨厌这样做。

connectunix_socket作为参数,该参数是UNIX套接字文件的路径。 MySQLdb不会读取你的my.cnf(按设计)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM