Bug #44824 mysql_real_connect() does not read my.cnf correctly
Submitted: 12 May 2009 14:13 Modified: 15 May 2009 7:19
Reporter: A B Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: C API (client library) Severity:S3 (Non-critical)
Version:4.1, 5.0, 5,1, 6.0 bzr OS:Any
Assigned to: CPU Architecture:Any

[12 May 2009 14:13] A B
Description:
the packet 5.1.34 comes with socket at /var/run/mysql 
the older 5.1.32 had /var/lib/mysql

we changed the socket entry in /etc/my.cnf back into /var/lib/mysql 
and wondered why we could not connect to the database (mysql_real_connect() failed). 
but when we added  

mysql_options(&MySQL,MYSQL_READ_DEFAULT_FILE,"/etc/my.cnf");

everything worked as expected.

note: the problem arose because older libmylsqlclient in the system had the other path as fallback.

system: OpenSuSE 11.1 Intel x86_64

How to repeat:
for us it was enought to change the path an use a simply c-programm to connect to the database.
[13 May 2009 5:17] Sveta Smirnova
Thank you for the report.

> everything worked as expected.

So what is the bug here?
[13 May 2009 7:19] A B
the bug is that mysql_real_connect() should read the conffile (here /etc/my.cnf) and act accordingly. The current version uses obviously some fallback, driving users nuts that expect that /etc/my.cnf will influence programm that use libmysqlclient.

if that is not done you have the situation we found that different versions of  libmysqlclient fallback to different socket(path)s and only one of two programms is working.

strings libmysqlclient.so.15  | grep mysql.sock
/var/lib/mysql/mysql.sock

strings libmysqlclient.so.16  | grep mysql.sock
/var/run/mysql/mysql.sock
[13 May 2009 7:50] Sveta Smirnova
Thank you for the feedback.

Verified as described.

Strange, but if specify just mysql_options(mysql,MYSQL_READ_DEFAULT_GROUP,"your_prog_name"); program will read options in [client] section in /etc/my.cnf as well.
[14 May 2009 20:14] Omer Barnir
The need to call mysql_options() in order to make mysql_real_connect() use the cnf file is the expected behavior. See http://dev.mysql.com/doc/refman/5.1/en/mysql-real-connect.html
[15 May 2009 7:19] A B
@Omer BarNir:

if you mean with cnf file "my-home-brew-cnf-file" i agree. but we are talking
about the general my.cnf that is not read with the current mysql_real_connect()
and THAT is a surprise.

Sveta Smirnova is surprised that if you specify a new cnf.file the code still reads the client section of my.cnf i guess to make sure that there is a propper init and that is a feature document only in the example end of the page.