perl DBI 连接数据库报错 回复mysql.sock

perl DBI 连接数据库报错 解决

 

安装好DBI 之后 运行perl 程序 报错 :

 

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

但是 可以正常启动 mysql

 

#!/usr/bin/perl  -w
use strict;
use DBI;

my $dbh = DBI->connect("DBI:mysql:database=solrclient;host=localhost","suse","suse", {'RaiseError' => 1});


$dbh->disconnect();

 

于是

 

cd /tmp/

发现这个目录下确实没有  mysql.sock 这个文件 而 '/var/run/mysql/mysql.sock'  这个目录下却有

 

于是

 

vi /etc/my.cnf

 

# The following options will be passed to all MySQL clients
[client]
#password       = your_password
port            = 3306
socket          = /tmp/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port            = 3306
socket          = /tmp/mysql.sock

 

将 socket 更改为  /tmp/mysql.sock

 

然后 ps -ef |grep  mysql

将查询到的 所有进程都 kill -9

之后

 

 

 

/etc/init.d/mysql start

或者

service mysql start

 

find  / -name  mysql.sock  查找 mysql.sock 的位置

 

mysql 启动不起来可能原因:

 

mysql.sock 文件的权限不是 mysql:mysql

 

 

 

你可能感兴趣的:(mysql)