DBI cannot connect to mysql at a specified socket location

Z

Zhiqiang Ye

Dear all,
I encountered this problem:
When I start the mysql daemon using the default configuration( that is ,
don't use $HOME/.my.cnf file)
then mysql's socket is located at /tmp/mysql.sock
And, my perl dbi script can work well.

But if I start the mysql daemon using the $HOME/.my.cnf file ( it specifies
the socket location : $HOME/tmp,
port is 2001 not 3306), mysqld is work at $HOME/tmp/mysql.socket.
At this time, the command line of connecting mysql works OK. (mysql -u
root -p ), it can automatically
find the socket location.
But the perl dbi script doesn't work. It tries to open the socket at
/tmp/mysql.sock, of course , it can
not connect to mysql.

Is there any method to specify the socket's location for perl DBI to find
mysql.sock?
Thank you very much. The code looks like this:

use strict;
use DBI;

my $database="test";
my $hostname="localhost";
my $cnf_file="/home/somebody/.my.cnf";
my $usr = "root";
my $password = "123456";


my $dsn="DBI:mysql:$database; mysql_socket=/home/somebody/tmp/mysql.sock";
my $dbh=DBI->connect($dsn,$usr,$password) or die "$DBI::errstr";
 
G

gnari

Zhiqiang Ye said:
Dear all,
I encountered this problem:
When I start the mysql daemon using the default configuration( that is ,
don't use $HOME/.my.cnf file)
then mysql's socket is located at /tmp/mysql.sock
And, my perl dbi script can work well.

But if I start the mysql daemon using the $HOME/.my.cnf file ( it specifies
the socket location : $HOME/tmp,

totally uninformed guess:
try /home/somebody/tmp

maybe the .my.cnf file does not expand $HOME

gnari
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top