前言
测试环境的一个小问题,放好久了,今天正好有时间解决,解决方法很简单,维稳处理,不重启数据库服务,不改配置文件
问题
直接用命令登录数据库,登不上去
# mysql -uroot -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
提示访问不到socket
原因
根据配置文件“/etc/my.cnf”的路径,未找到相应的socket文件,就会引发此错误
解决
这里就不改配置文件,因为虽然测试环境,但也是有人用的,等晚上处理没那耐心,所以按下面方法处理问题
寻找sock文件
先找sock文件,用find命令,从根目录开始找,/var/lib/mysql/mysql.sock这个这个就是,至于mysqlx.sock是以前装mysql剩下的,不足为提
# find / -name "*.sock"
/run/rpcbind.sock
/var/lib/mysql/mysql.sock
/tmp/mysqlx.sock
创建软连接
# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
问题解决
# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3930036
Server version: 8.0.18 MySQL Community Server - GPL
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>