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

输入 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试下

上一篇:Oracle 语法


下一篇:mysql安装错误之->ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)