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 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 ~]#
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)