在 CentOS/RHEL 系統上以 RPM 方式升級 MySQL 時,常遭遇「MySQL conflicts with mysql-5.0.22」等依賴衝突,甚至因共享庫 libmysqlclient.so.15 被多個套件依賴而無法直接移除。本文記錄一次完整的衝突排查與清理實戰,提供可復用的標準化流程。
rpm -Uvh MySQL-server-community-5.0.67-0.rhel5.i386.rpm
error: Failed dependencies:
MySQL conflicts with mysql-5.0.22-2.1.0.1.x86_64
MySQL conflicts with mysql-5.0.22-2.1.0.1.i386
MySQL-server conflicts with mysql-server-5.0.22-2.1.0.1.x86_64
rpm -q mysql
# 輸出兩行:mysql-5.0.22-2.1.0.1 (x86_64 / i386 並存)
rpm -e --nodeps mysql-5.0.22-2.1.0.1
error: "mysql-5.0.22-2.1.0.1" specifies multiple packages
rpm -e --allmatches mysql-5.0.22-2.1.0.1
error: Failed dependencies:
libmysqlclient.so.15()(64bit) is needed by perl-DBD-MySQL-3.0007-1.fc6.x86_64
libmysqlclient.so.15()(64bit) is needed by mysql-server-5.0.22-2.1.0.1.x86_64
...(共 20+ 個依賴項)
# 逐個移除依賴該共享庫的套件
rpm -e perl-DBD-MySQL-3.0007-1.fc6.x86_64
rpm -e mysql-server-5.0.22-2.1.0.1.x86_64
rpm -e libdbi-dbd-mysql-0.8.1a-1.2.2.x86_64
rpm -e dovecot-1.0-1.2.rc15.el5.x86_64
rpm -e mysql-connector-odbc-3.51.12-2.2.x86_64
rpm -e MySQL-python-1.2.1-1.x86_64
# 最後清理核心套件
rpm -e --allmatches mysql-5.0.22-2.1.0.1
# 輸出:成功
rpm -Uvh MySQL-server-community-5.0.67-0.rhel5.i386.rpm
# 輸出:成功
yum remove mysql* 會自動處理依賴拓撲,避免手動遞歸。tar czf /backup/mysql-$(date +%F).tar.gz /var/lib/mysql。避坑提醒: 生產環境嚴禁直接 rpm -e --nodeps 核心庫套件,極易導致殘留檔案污染新安裝。