CentOS 7 无法安装MySQL 5.7,始终尝试安装MariaDB求助
Hey there, let's work through this frustrating installation problem. Those cPanel-related MySQL packages you're seeing (cpanel-mysql-5.1.73-1.cp1156.x86_64 and cpanel-perl-524-DBD-mysql-4.042-1.cp1168.x86_64) are almost certainly conflicting with your attempt to install official MySQL 5.7, and there might still be residual repo settings pushing MariaDB instead. Here's a step-by-step fix:
Step 1: Remove Conflicting cPanel MySQL Packages
First, we need to eliminate those old cPanel-managed MySQL packages since they're competing with the official MySQL repo. Important: Back up any existing databases first if you have data you want to keep! Then use the --nodeps flag to force uninstall:
rpm -e --nodeps cpanel-mysql-5.1.73-1.cp1156.x86_64 cpanel-perl-524-DBD-mysql-4.042-1.cp1168.x86_64
Step 2: Fully Disable MariaDB Repositories
Just using yum-config-manager might not be enough—let's make sure no MariaDB repos are active:
- Rename any MariaDB repo files to disable them outright:
mv /etc/yum.repos.d/MariaDB.repo /etc/yum.repos.d/MariaDB.repo.disabled - Double-check other system repos (like CentOS base repos) to ensure they don't include MariaDB in their package lists. If you find any MariaDB sections, edit the repo file and set
enabled=0.
Step 3: Verify MySQL 5.7 Repo is Enabled
Confirm the MySQL 5.7 repo is the only active MySQL repo:
- Enable MySQL 5.7 and disable newer versions (like 8.0) with these commands:
yum-config-manager --enable mysql57-community yum-config-manager --disable mysql80-community - You can also manually edit
/etc/yum.repos.d/mysql-community.repoto ensure this section is correctly set:
Set[mysql57-community] name=MySQL 5.7 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysqlenabled=0for all othermysql*-communitysections in the file.
Step 4: Clear Yum Cache & Refresh
Outdated cache might still be pointing to MariaDB. Clear it and rebuild the cache to get fresh package info:
yum clean all rm -rf /var/cache/yum yum makecache
Step 5: Install MySQL 5.7
Now try installing again, explicitly targeting the official MySQL 5.7 package:
yum install mysql-community-server
If you still see MariaDB being pulled in, add a flag to exclude all MariaDB repos:
yum install mysql-community-server --disablerepo=*mariadb*
Step 6: Verify Installation
Once installed, start and enable the MySQL service to make it run on boot:
systemctl start mysqld systemctl enable mysqld
Check the installed version to confirm success:
mysql --version
Quick Heads-Up
If you were using the cPanel MySQL instance before, double-check that you backed up all databases with mysqldump before uninstalling the cPanel packages—this prevents data loss when switching to the official MySQL 5.7.
内容的提问来源于stack exchange,提问作者phlipinmi

