Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’解决方法

用XAMPP装装好mysql之后,mysql -u root -p 连不上,报这个错误:

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’

在mysql的配置文件里,/opt/lampp/etc/my.cnf, 发现了这样的配置:

[java]
<span style=”font-size:24px;”># The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
socket = /opt/lampp/var/mysql/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
user = nobody
port = 3306
socket = /opt/lampp/var/mysql/mysql.sock

</span>

原来mysql用的套接字文件是:/opt/lampp/var/mysql/mysql.sock于是建立了个软连接, 命令如下。不能建立硬链接,不知道为什么。
ln -s /opt/lampp/var/mysql/mysql.sock /var/run/mysqld/mysqld.sock

现在可以用mysql -uroot命令登陆上了~

方法2:
mysql –help
mysql –socket=/opt/lampp/var/mysql/mysql.sock

方法3
比较彻底解决的方法
找到lampp中的my.cnf文件
cp /opt/lampp/etc/my.cnf /etc/mysql
将你的配置文件拷贝到etc/mysql下

贾定强微信

微信扫一下,或点击链接添加好友