CentOS 7 安装 MySQL 8.0x,踩坑记录
具体安装步骤,推荐参考这篇文章的第一部分【YUM方式】来安装:
https://segmentfault.com/a/1190000037702065
如果出现 Can't connect to local MySQL server through socket '/tmp/mysql.sock'
,
可以参考这篇文章 https://developer.aliyun.com/article/435802,在 /etc/my.cnf 中添加配置文件:
重启 MySQL 的方法:
# 查看状态:
systemctl status mysqld
# 重启:
systemctl restart mysqld
root 用户连接 MySQL 时:
[root@onepiece ~]# mysql -uroot -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (13)
而 mysql 用户连接是没有问题的:
[root@onepiece ~]# su - mysql
Last login: Sat Nov 27 13:32:03 CST 2021 on pts/2
-sh-4.2$
-sh-4.2$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 18
Server version: 8.0.27 MySQL Community Server - GPL
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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> exit
参考博客:https://blog.csdn.net/hjf161105/article/details/78850658
原因大概是:在安装 MySQL 服务的时候,/tmp/mysql.sock 是关联了 mysql 用户创建的套接字,root 用户要连接 MySQL,应该重新创建套接字,比如这样:
[root@onepiece ~]# mysql -h127.0.0.1 -P3306 -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 19
Server version: 8.0.27 MySQL Community Server - GPL
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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> exit
Bye
[root@onepiece ~]#