簡體   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