最近在使用 CentOS 操作系統在線下載 MySQL 數據庫的時候遇到了一個問題,提示出現 404 錯誤。
[root@localhost ~]# yum install mysql Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirror.lzu.edu.cn * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com No package mysql available. Error: Nothing to do
從錯誤信息中可以看出,沒有找到需要安裝的 MySQL 軟件包。但是,在執行 yum search mysql 命令后可以看到當下最新的 MySQL 版本已經發布。
MySQL-server.x86_64 8.0.19-1.el7 mysql80-community MySQL-client.x86_64 8.0.19-1.el7 mysql80-community MySQL-shared.x86_64 8.0.19-1.el7 mysql80-community MySQL-devel.x86_64 8.0.19-1.el7 mysql80-community MySQL-test.x86_64 8.0.19-1.el7 mysql80-community MySQL-connector-odbc.x86_64 8.0.19-1.el7 mysql80-community ...
原因在于 CentOS 默認源中不提供 MySQL 相關的軟件包,因此需要手動添加 MySQL 的軟件源。
[root@localhost ~]# vim /etc/yum.repos.d/mysql-community.repo
在新建的 mysql-community.repo 文件中輸入以下內容:
[mysql-connectors-community] name=MySQL Connectors Community baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/$releasever/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql [mysql-tools-community] name=MySQL Tools Community baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/$releasever/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql [mysql80-community] name=MySQL 8.0 Community Server baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/$releasever/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
保存并退出后,再次執行 yum install mysql 命令即可成功安裝 MySQL。
[root@localhost ~]# yum install mysql Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirror.lzu.edu.cn * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com mysql57-community | 2.5 kB 00:00:00 mysql-connectors-community | 2.5 kB 00:00:00 mysql-tools-community | 2.5 kB 00:00:00 mysql80-community | 2.5 kB 00:00:00 mysql80-community/primary_db | 135 kB 00:00:00 Resolving Dependencies ...
通過該方法,可以在 CentOS 上成功安裝 MySQL 相關軟件包。