在 RHEL/CentOS 6.x 安裝 MySQL 官方 RPM 套件時,常因系統預裝 mysql-libs-5.1.x 導致檔案衝突。本文記錄完整衝突現象、依賴阻礙分析、--nodeps 強制移除流程與後續驗證,並提供更優雅的 yum swap 替代方案。
[root@localhost tmp]# rpm -ivh MySQL-server-advanced-5.6.20-1.rhel5.x86_64.rpm
Preparing... ########################################### [100%]
file /usr/share/mysql/czech/errmsg.sys from install of MySQL-server-advanced-5.6.20-1.rhel5.x86_64 conflicts with file from package mysql-libs-5.1.73-3.el6_5.x86_64
file /usr/share/mysql/danish/errmsg.sys ... conflicts ...
... (大量語言檔案衝突) ...
[root@localhost tmp]# rpm -qa | grep -i mysql
mysql-libs-5.1.73-3.el6_5.x86_64
[root@localhost tmp]# rpm -ev mysql-libs-5.1.73-3.el6_5.x86_64
error: Failed dependencies:
libmysqlclient.so.16()(64bit) is needed by (installed) postfix-2:2.6.6-6.el6_5.x86_64
libmysqlclient.so.16(libmysqlclient_16)(64bit) is needed by (installed) postfix-2:2.6.6-6.el6_5.x86_64
mysql-libs is needed by (installed) postfix-2:2.6.6-6.el6_5.x86_64
核心衝突:postfix 郵件服務依賴舊版 libmysqlclient.so.16。
[root@localhost tmp]# rpm -ev mysql-libs-5.1.73-3.el6_5.x86_64 --nodeps
[root@localhost tmp]#
⚠️ 風險警示:--nodeps 會破壞 postfix 的運行時依賴,導致郵件服務無法啟動。執行後**必須**重裝相容的 MySQL 共享庫。
cp -r /etc/postfix /etc/postfix.bakrpm -ev mysql-libs-5.1.73-3.el6_5.x86_64 --nodepsrpm -ivh MySQL-shared-5.6.20-1.rhel5.x86_64.rpm
# 或
rpm -ivh MySQL-shared-compat-5.6.20-1.rhel5.x86_64.rpm # 兼容舊版 soname
MySQL-shared-compat 同時提供 libmysqlclient.so.16/18/20,**完美解決 postfix 依賴**。
service postfix restartrpm -ivh MySQL-server-advanced-5.6.20-1.rhel5.x86_64.rpm若系統已配置 MySQL 官方 Yum 源:
# 直接替換套件,自動處理依賴
yum swap mysql-libs -- install MySQL-shared-compat-5.6.*
# 或使用 replace 插件
yum install yum-plugin-replace
yum replace mysql-libs -- replace-with MySQL-shared-compat-5.6.*
此方式**自動保護 postfix 等依賴服務**,無需手動干預,強烈推薦生產環境使用。
# 檢查共享庫
ls -l /usr/lib64/mysql/libmysqlclient.so*
# 測試 postfix
echo "test" | mail -s "test" root@localhost
tail -f /var/log/maillog
| 方案 | 優點 | 缺點 | 適用場景 |
|---|---|---|---|
| rpm --nodeps + 手動裝 compat | 可控、離線可用 | 風險高、步驟繁瑣 | 無網絡、舊版本無 Yum 源 |
| yum swap / replace | 自動依賴解決、服務無感 | 需配置官方 Yum 源 | **生產環境首選** |
| 卸載 postfix 後再裝 MySQL | 徹底乾淨 | 失去郵件功能 | 不需要 postfix 的服務器 |
rpm --nodeps 是最後手段MySQL-shared-compat 是解決舊版 soname 依賴的「萬金油」yum list installed | grep mysql 掃描潛在衝突