mysql连接数据库存报下面错误:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

时间:2021-11-27 00:30:59

输入 mysql -u root 登录 mysql 的时候出现以下错误:

mysql连接数据库存报下面错误:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

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

解决方法:

touch /var/lib/mysql/mysql.sock      (如果目录里没有这个文件就手动创建) mysql.sock的路径可以查看/etc/my.cnf文件

chmod 777 /var/lib/mysql/mysql.sock

ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock    (创建软链接)

然后重新运行mysql试下