yum update 一鍵滾動升級小版本(安全修復)。mysql-community-server、mysql-workbench、mysql-router、mysql-shell 等全套組件。# 進入官網下載頁:https://dev.mysql.com/downloads/repo/yum/
# 選擇對應 EL 版本(el7 / el8 / el9),下載 rpm
wget https://dev.mysql.com/get/mysql80-community-release-el7-7.noarch.rpm
# 安裝 repo 包(會在 /etc/yum.repos.d/mysql-community.repo 寫入配置)
sudo yum localinstall -y mysql80-community-release-el7-7.noarch.rpm
# 查看可用子倉庫
yum repolist all | grep mysql
# 禁用 8.0,啟用 5.7(示例)
sudo yum-config-manager --disable mysql80-community
sudo yum-config-manager --enable mysql57-community
# 或直接安裝指定版本包名
# sudo yum install mysql-community-server-5.7.44-1.el7
sudo yum install -y mysql-community-server mysql-community-client
# 5.7/8.0 首次啟動會自動初始化 data 目錄並生成臨時 root 密碼
sudo systemctl start mysqld
# 查看臨時密碼
sudo grep 'temporary password' /var/log/mysqld.log
# 2023-01-01T00:00:00.123456Z 1 [Note] A temporary password is generated for root@localhost: xYz#Abc123
# 登入並修改密碼(需滿足 validate_password 政策)
mysql -uroot -p"xYz#Abc123"
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewStrongPass@123';
UNINSTALL COMPONENT 'file://component_validate_password'; -- 如需簡單密碼可卸載密碼驗證插件
FLUSH PRIVILEGES;
root password update failed --skip-grant-tables現象:啟動參數帶 --skip-grant-tables 導致無法執行 ALTER USER。
# 1. 停止服務
sudo systemctl stop mysqld
# 2. 編輯 /etc/my.cnf 移除 skip-grant-tables(若有)
# 3. 正常啟動
sudo systemctl start mysqld
# 4. 重置密碼流程
sudo systemctl stop mysqld
sudo mysqld_safe --skip-grant-tables --skip-networking &
mysql -uroot
UPDATE mysql.user SET authentication_string='' WHERE User='root' AND Host='localhost';
FLUSH PRIVILEGES;
EXIT;
# 關閉 --skip-grant-tables 進程
pkill mysqld_safe
sudo systemctl start mysqld
mysql -uroot -e "ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewStrongPass@123';"
GPG check failedsudo rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2023
# 或 yum 配置 gpgcheck=0(不推薦生產)
sudo yum update mysql-community-server(自動備份、停服、升級、啟動、運行 mysql_upgrade)。mysql_upgrade。sudo systemctl stop mysqld
sudo yum remove -y mysql-community-*
sudo rm -rf /var/lib/mysql /var/log/mysqld.log /etc/my.cnf /etc/my.cnf.d
sudo userdel mysql 2>/dev/null; sudo groupdel mysql 2>/dev/null