DBD:mysql doesn't read mysql option file /etc/my.cnf file

J

JL

Platform: Linux Red Hat RHEL 3 (and red hat 9)

Installed MySQL from source. As a matter of fact, installed all LAMPS
from source, and the mysql socket file was arranged in a place other
than /tmp/mysql.sock. Let's say, /opt/mysql_root/sock/mysql.sock.
Installed DBI without any problem.

In /etc/my.cnf there are lines as
----- ----- -----
[client]
socket = /opt/mysql_root/sock/mysql.sock
....
[mysqld]
socket = /opt/mysql_root/sock/mysql.sock
....
----- ----- -----
The access rights issues to the directory was taken care off.


The problem came when installing DBD::mysql from source.

perl Makefile.Pl
make

make test => problem begins:

----- excerpt -----
....
....
.... error: ..."can't connect to local mysql server through socket
/tmp/mysql.sock" ...
....

.... [Error 2]

------ end ------

I have built everything from source, so there shouldn't be a problem of
"mysql server was built with binary and the others were built with
different packages, such as using the package from Linux o/s, etc."
And the mysqld was running while DBD installation was being progressed.

I didn't have problem with shell command line connecting to the server,
and code in PHP that connects to the server worked fine.

It seems that DBD::mysql doesn't (or doesn't have the intelligence to)
check /etc/my.cnf file when starting mysql client. I have tried

# ln -s /opt/mysql_root/sock/mysql.sock /tmp/mysql.sock

and the problem was solved. I prefer not to use this method.

Maybe rebuilding mysql with
"--with-unix-socket-path=/opt/mysql_root/sock/mysql.sock" will solve
the problem?

Or, setting shell variable
"MYSQL_UNIX_PORT=/opt/mysql_root/sock/mysql.sock" will do, too. So in
perl code, before we start db connection, we can set
$ENV{'MYSQL_UNIX_PORT'} = "/opt/mysql_root/sock/mysql.sock"?

I am trying to solve this problem at the system building phase, and to
avoid having to modify the original perl code, for example, from:
--
$dsn = "DBI:mysql:test";
$dbh = DBI->connect($dsn, $user, $password);
--

to

--
$dsn = "DBI:mysql:test;mysql_read_default_group=client;"
. "mysql_read_default_file=/usr/local/mysql/data/my.cnf";
$dbh = DBI->connect($dsn, $user, $password);
--

so that the old perl code can be ported to the newly installed system
without modification.



Appreciate your expertise
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top