首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫

CentOS 6.5 在線 YUM 安裝 MySQL 8.0 快速部署指南

     編輯:MySQL 資料庫相關知識

清理舊版本 MySQL

# 按依賴順序從下往上卸載
rpm -e --nodeps qt-MySQL-4.6.2-26.el6_4.x86_64
rpm -e --nodeps mysql-server-5.1.71-1.el6.x86_64
rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64
rpm -e --nodeps mysql-devel-5.1.71-1.el6.x86_64
rpm -e --nodeps mysql-5.1.71-1.el6.x86_64

# 驗證清理乾淨
rpm -qa | grep -i mysql

配置官方 YUM 源

cd /etc/yum.repos.d/
cat > mysql.repo << 'EOF'
# Enable to use MySQL 8.0
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=https://repo.mysql.com/yum/mysql-8.0-community/el/6/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
EOF

驗證源可用性

yum repolist enabled | grep mysql
# 輸出應包含 mysql80-community

安裝 MySQL 8.0 核心套件

yum install -y \
mysql-community-common \
mysql-community-libs \
mysql-community-client \
mysql-community-server \
mysql-community-devel

啟動與初始化

service mysqld start
service mysqld status

首次啟動會自動:

  1. 初始化數據目錄
  2. 生成 SSL 證書鑰匙
  3. 安裝 validate_password 插件
  4. 創建 root@localhost 並生成隨機密碼

獲取臨時密碼並修改

# 查看隨機密碼
grep 'temporary password' /var/log/mysqld.log
# 輸出示例:2023-01-01T00:00:00.000000Z 1 [Note] A temporary password is generated for root@localhost: xYz#123Abc

# 登入並修改密碼(需符合 validate_password 政策:長度、大小寫、數字、特殊字符)
mysql -uroot -p'xYz#123Abc'
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewStrongPass#123';

配置遠程訪問權限

-- 允許 root 從任意主機連接(生產環境建議創建專用用戶)
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'NewStrongPass#123' WITH GRANT OPTION;
FLUSH PRIVILEGES;

設置開機自啟

chkconfig mysqld on

防火牆放行 3306 端口

iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
service iptables save

快速驗證腳本

cat > /usr/local/bin/mysql_health_check.sh << 'EOF'
#!/bin/bash
mysql -uroot -p'NewStrongPass#123' -e "SELECT VERSION(); SHOW VARIABLES LIKE 'character_set_server';"
EOF
chmod +x /usr/local/bin/mysql_health_check.sh
mysql_health_check.sh

遷移建議:從 5.x 升級到 8.0

  1. 備份:mysqldump --all-databases --single-transaction --routines --triggers > backup_5x.sql
  2. 檢查兼容性:mysqlcheck --all-databases --check-upgrade
  3. 升級後執行:mysql_upgrade -uroot -p
  4. 重建統計信息:ANALYZE TABLE 核心業務表
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved