更新记录
点击查看
2024年3月1日 更新常见问题。
2024年2月29日 发布。
安装需要使用到的命令和包
如果有就不用安装了。
yum -y install tar
yum -y install vim
yum -y install net-tools
yum -y install libncurses*
下载 MySQL 的安装包
官网地址:https://downloads.mysql.com/archives/community/
5.7版本
8.X 版本
下载到服务器
# 5.7
wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.44-1.el7.x86_64.rpm-bundle.tar
# 8.2
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.2.0-1.el7.x86_64.rpm-bundle.tar
解压安装包
tar -xvf mysql-5.7.44-1.el7.x86_64.rpm-bundle.tar
按顺序安装包
分别安装common , libs, client, server服务
rpm -ivh mysql-community-common-5.7.44-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.44-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.44-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.44-1.el7.x86_64.rpm
查看MySQL
安装情况
rpm -qa | grep mysql
初始化数据库
mysqld --initialize --console
查看初始密码
cat /var/log/mysqld.log | grep password
启动 MySQL 服务
# 查看MySQL状态
systemctl status mysqld
# 启动 MySQL 服务
systemctl start mysqld
## 如果启动失败执行下面这个。然后再启动
chown -R mysql:mysql /var/lib/mysql
## 如果还是启动失败执行下面这个。然后再启动
chmod 777 /usr/sbin/mysqld
chmod 777 /usr/lib/mysql/*
首次登陆
mysql -uroot -p
#输入刚刚查询到的秘密
# 修改默认的密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
## 修改root密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'very_strong_password';
# 允许root可以远程访问(危险)
use mysql;
update user set host='%' where user='root';
# 或者创建一个新用户(MySQL 8前)
GRANT ALL PRIVILEGES ON *.* TO panda@"%" IDENTIFIED BY 'very_strong_password' WITH GRANT OPTION;
# 或者创建一个新用户(MySQL 8后)
CREATE USER panda@'%' IDENTIFIED BY 'very_strong_password';
GRANT ALL PRIVILEGES ON *.* TO panda@"%" WITH GRANT OPTION;
## 刷新权限
FLUSH PRIVILEGES;
Linux 防火墙设置
# 设置防火墙开启3306端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
# 重启防火墙服务
systemctl restart firewalld.service
## 关闭防火墙(不需要执行,备用记录)
systemctl disable firewalld
常见问题
提示缺少libcrypto.so.10包
Failed dependencies:
libcrypto.so.10()(64bit) is needed by mysql-community-server-8.2.0-1.el7.x86_64
libcrypto.so.10(OPENSSL_1.0.1_EC)(64bit) is needed by mysql-community-server-8.2.0-1.el7.x86_64
libcrypto.so.10(OPENSSL_1.0.2)(64bit) is needed by mysql-community-server-8.2.0-1.el7.x86_64
libcrypto.so.10(libcrypto.so.10)(64bit) is needed by mysql-community-server-8.2.0-1.el7.x86_64
libssl.so.10()(64bit) is needed by mysql-community-server-8.2.0-1.el7.x86_64
libssl.so.10(libssl.so.10)(64bit) is needed by mysql-community-server-8.2.0-1.el7.x86_64
mysql-community-icu-data-files = 8.2.0-1.el7 is needed by mysql-community-server-8.2.0-1.el7.x86_64
解决办法:
# 安装系统对应架构的包
wget http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/compat-openssl10-1.0.2o-3.el8.x86_64.rpm
rpm -ivh compat-openssl10-1.0.2o-3.el8.x86_64.rpm
参考资料
https://www.openeuler.org/zh/blog/20220726-banqian-mysql/banqian-mysql.html
https://zhuanlan.zhihu.com/p/624316835
https://forum.openeuler.org/t/topic/1602
https://blog.csdn.net/sinat_20260363/article/details/128922998