MySQLPython ignores my my.cnf file. Where does he get the information from?

When I try to use MySQLPython (via SQLAlchemy), I get an 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 

but no other mysql client on my machine notices!

My file 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 

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

I checked that ~ / .my.cnf and /var/lib/mysql/my.cnf do not override it. Mysql5 client program, etc. It has no connection problems, as well as installing groovy / grails on the same computer 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> 

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

+4
source share
4 answers

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

+4
source

MysqlDBlib does not read /etc/my.cnf by default. Adding read_default_group = "client" to the MySQLdb.connect call will force it to read the client section.

+3
source

FWIW: I “fixed” it by changing the location of the .sock file in my.cnf where MySQLdb wanted (/opt/local/var/run/mysql5/mysqld.sock), but I hate doing something like that.

+2
source

connect takes unix_socket as a parameter, which is the path to the UNIX socket file. MySQLdb will not read your my.cnf (by design).

+1
source

Source: https://habr.com/ru/post/1311365/


All Articles