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 ~]#

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章