我的系统上mysql.sock的位置是/usr/local/mysql5/mysqld.sock
thrilllap-2:tmp reuven$ mysqld --print-defaults mysqld would have been started with the following arguments: --socket=/usr/local/mysql5/mysqld.sock --port=3306
当我尝试从flask通过sqlalchemy使用mysql时,得到:
File "build/bdist.macosx-10.6-intel/egg/MySQLdb/connections.py", line 187, in __init__ sqlalchemy.exc.OperationalError: (OperationalError) (2002, "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)") None None
mysql程序正确连接到数据库,系统上的所有其他mysql客户端也是如此。
我的my.cnf具有正确的套接字位置
[client] port = 3306 socket = /usr/local/mysql5/mysqld.sock [safe_mysqld] socket = /usr/local/mysql5/mysqld.sock [mysqld_safe] socket = /usr/local/mysql5/mysqld.sock [mysqld] socket = /usr/local/mysql5/mysqld.sock port = 3306
基本的“ SQLAlchemy”库具有一个选项,你可以在其中指定mysql.sock的位置,但是这不会通过sqlalchemy / flask库公开
http://packages.python.org/Flask-SQLAlchemy/config.html
我的问题:
你必须找出确切的语法,但对于MySQL,我认为它们使用unix_socket查询选择。就像是:
unix_socket
mysql:///dbname?unix_socket=/opt/mysql/mysql.sock'
应该是SQLAlchemy的连接URI。