全新安装 CentOS 7
# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
yum -y install mariadb-server mariadb
# mysql -V
mysql Ver 15.1 Distrib 5.5.52-MariaDB, for Linux (x86_64) using readline 5.1
/usr/bin/mysql_secure_installation
Enter current password for root (enter for none):
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
Enter current password for root (enter for none):
mysqladmin password newpassword
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/var/lib/mysql/mysql.sock' exists!
检查 /var/lib/mysql/
la /var/lib/mysql/
# ls /var/lib/mysql/
aria_log.00000001 aria_log_control ibdata1 ib_logfile0 ib_logfile1 mysql performance_schema test
知道为什么会发生这种情况吗?以及如何修复
答案1
您收到的错误是:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
2 是 ENOENT,或 No such file or directory。这意味着套接字不存在。原因是 MariaDB 没有运行。您需要先启动 MariaDB,然后再运行mysql_secure_installation
。
systemctl start mariadb