CentOS 7中安裝 MySQL 出現了 No package mysql-server available. Error: Nothing to do 錯誤


CentOS 7 安裝 mysql-server 爬坑

發現問題

在centos 6安裝 mysql-server是直接使用命令 yum -y install mysql-server ,但是在CentOS 7中出現了 No package mysql-server available. Error: Nothing to do 錯誤。詳細錯誤信息如下:

[root@laona ~]# yum -y install mysql-server
Loaded plugins: fastestmirror
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository contrib is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: mirrors.cloud.aliyuncs.com
 * extras: mirrors.cloud.aliyuncs.com
 * updates: mirrors.cloud.aliyuncs.com
No package mysql-server available.
Error: Nothing to do

解決方案

使用 MariaDB 代替 MySQL 命令即可

產生原因

簡單來說,MariaDB 是 MySQL 的fork,兩者關系就好比 Red Hat 和 CentOS 的關系。從 MySQL 變成了 Oracle 甲骨文公司的產品后,MySQL 就已經從 RHEL 和 CentOS 所提供的套件清單移除了。

安裝 MySQL

1. 安裝 mariadb 與 mariadb-server 套件

sudo yum -y install mariadb mariasb-client

2. 啟動 MySQL 服務

sudo systemctl start mariadb

3. 啟動 MariaDB 服務,讓 MariaDB 服務每次開機會自啟

sudo systemctl enable mariadb

4. 檢查啟動狀態

sudo systemctl status mariadb

5. 加強 MariaDB 安裝的安全性

sudo mysql_secure_installation

這個shell主要是有以下作用:
- 設定 root 賬號的密碼
- 禁止 root 叢非本人登錄
- 移除 anonymous 匿名用戶登錄
- 移除測試數據庫

6. 查詢版本號

mysql -v

登錄測試

鍵入以下指令,輸入密碼即可。

mysql -u root -h localhost -p


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM