MySQLPython忽略了my.cnf文件.它从哪里获得信息? [英] MySQLPython is ignoring my my.cnf file. Where does it get its information?

查看:118
本文介绍了MySQLPython忽略了my.cnf文件.它从哪里获得信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试通过SQLAlchemy使用MySQLPython时出现错误

When I try to use MySQLPython (via SQLAlchemy) I get the error

 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客户端能正常运行!

but no other mysql client on my machine sees it fine!

我的my.cnf文件指出:

My my.cnf file states:

[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

and the mysql.sock file is, indeed, located in /tmp/mysql

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

I verified that ~/.my.cnf and /var/lib/mysql/my.cnf aren't overriding it. The mysql5 client program, etc, has no trouble connecting and neither does a groovy/grails installation on the same machine using jdbc/mysql connection

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文件,该怎么看?

Why can't MySQLdb for python figure this out? Where would it look if not the my.cnf files?

推荐答案

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

Have you tried adding the option read_default_file='~/.my.cnf' to your connect() call, to tell the Python database driver to read your configuration file? I think that otherwise it ignores the file by default.

这篇关于MySQLPython忽略了my.cnf文件.它从哪里获得信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆