CentOS 7 系統盤不再預設提供 mysql-server RPM 包,需透過 MySQL 官方 Yum Repository 進行安裝。本文記錄配置 Repo、解決 GPG Key 錯誤並成功安裝 MySQL 5.6/5.7 的實戰過程。
在 /etc/yum.repos.d/ 建立 mysql-community.repo:
# Enable to use MySQL 5.6 [mysql56-community] name=MySQL 5.6 Community Server baseurl=https://repo.mysql.com/yum/mysql-5.6-community/el/5/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Note: MySQL 5.7 is currently in development. For use at your own risk. # Please read with sub pages: https://dev.mysql.com/doc/relnotes/mysql/5.7/en/ [mysql57-community-dmr] name=MySQL 5.7 Community Server Development Milestone Release baseurl=https://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
yum install mysql-community-server
若遇到錯誤:GPG key retrieval failed: [Errno 14] curl#37 - "Couldn't open file /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql"
原因是本地缺少 GPG Key 檔案,修改 Repo 設定關閉 GPG 檢查:
[mysql56-community] name=MySQL 5.6 Community Server baseurl=https://repo.mysql.com/yum/mysql-5.6-community/el/5/$basearch/ enabled=1 gpgcheck=0
重新執行安裝即可成功:
yum install mysql-community-server
systemctl start mysqldsystemctl enable mysqldmysql_secure_installationfirewall-cmd --permanent --add-port=3306/tcp