rpm -qa | grep mysql
如果已经安装了 MySQL,您可以通过以下步骤卸载它。
rpm -ev mysql80-community-release-el7-7.noarch
rpm -ev mysql-community-client-plugins-8.0.22-1.ky3.kb1.x86_64
下载地址:MySQL :: Download MySQL Community Server (Archived Versions)
CentOS 是 RedHat 的一个分发版本,功能与 RedHat 完全一致
注:请确保版本对应,以下是版本为 8.0.32 的示例包:
mysql-community-client-8.0.32-1.el7.x86_64.rpm
mysql-community-client-plugins-8.0.32-1.el7.x86_64.rpm
mysql-community-common-8.0.32-1.el7.x86_64.rpm
mysql-community-icu-data-files-8.0.32-1.el7.x86_64.rpm
mysql-community-libs-8.0.32-1.el7.x86_64.rpm
mysql-community-server-8.0.32-1.el7.x86_64.rpm
将下载好的 RPM 包拷贝至服务器,然后按照以下顺序安装,或按照提示安装:
rpm -ivh mysql-community-client-plugins-8.0.32-1.el7.x86_64.rpm
rpm -ivh mysql-community-common-8.0.32-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.32-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.32-1.el7.x86_64.rpm
rpm -ivh mysql-community-icu-data-files-8.0.32-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.32-1.el7.x86_64.rpm
重启 MySQL 服务
systemctl start mysqld.service
检查 MySQL 服务运行状态
systemctl status mysqld.service
停止 MySQL 服务
systemctl stop mysqld.service
重启 MySQL 服务
systemctl restart mysqld.service
grep 'temporary password' /var/log/mysqld.log
# -h 指定 IP 地址
mysql -u root -p
输入上述命令获取的密码。
ALTER USER 'root'@'localhost' IDENTIFIED BY 'PASSWD';
CREATE USER 'username'@'host' IDENTIFIED BY 'password';
USE mysql;
SELECT host, user FROM user;
UPDATE user SET host = '%' WHERE user = 'root';
systemctl restart mysqld.service
本教程适用于测试环境,出于安全性考虑,在生产运行环境下应遵循以下建议:
# 如果显示 "running",则表示防火墙已开启
firewall-cmd --state
systemctl stop firewalld.service
systemctl start firewalld.service
systemctl disable firewalld.service
systemctl enable firewalld.service