mysql连接报错:Error: Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2)

解决:cd到这个目录看一下有没有这个文件,有就删除重启,没有就直接重启,因为重启会自动新建这个文件。

第一步:cd到文件

cd /var/lib/mysql/

第二步:删除这个文件,如果说报错删除失败说明没有这个文件。

rm  mysql.sock

第三步:关闭、重启mysql

systemctl stop mysqld
systemctl start mysqld

之后mysql -u root -p就可以正常打开了,注意删完mysql.sock退回原路径。

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
This error message indicates that the MySQL server on the local machine is not running or is not configured properly. The MySQL server uses a Unix socket file located at /var/lib/mysql/mysql.sock to communicate with client applications. If this socket file is missing or inaccessible, client applications cannot connect to the MySQL server. To resolve this error, try the following steps: 1. Check if MySQL server is running: Open a terminal window and enter the command 'systemctl status mysql.service'. If the output shows that the service is not running, try starting it using the command 'systemctl start mysql.service'. 2. Check the socket file path: Verify that the socket file is located at /var/lib/mysql/mysql.sock. If the file is missing or located elsewhere, update the MySQL configuration file (/etc/mysql/my.cnf) to use the correct path for the socket file. 3. Check file permissions: Verify that the socket file has the correct permissions that allow the MySQL server to access it. The file should be owned by the mysql user and group with read and write permissions for the owner and group. Use the command 'ls -l /var/lib/mysql/mysql.sock' to check the file permissions. 4. Restart MySQL server: If you have made changes to the MySQL configuration file, restart the MySQL server using the command 'systemctl restart mysql.service'. If none of these steps resolve the issue, there may be a more serious problem with the MySQL server installation or configuration. Consider checking the MySQL error log (/var/log/mysql/error.log) for more information about the error.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值