1. 程式人生 > >python實踐學習之《問題:centos7安裝mysql-devel出現包依賴問題》

python實踐學習之《問題:centos7安裝mysql-devel出現包依賴問題》

背景

    我們使用的作業系統是centos7.3版本,之前此機器上通過編譯安裝了5.7版本的mysql。

    我們需要在linux(centos7)上面使用python連線mysql資料庫,進行資料的查詢,所以我們進行了下面的步驟的嘗試:

1、匯入第三方MySQL-python包操作,但是報錯:EnvironmentError: mysql_config not found,經過查詢發現是缺少mysql-devel包,於是開始了下面的第2步;

2、安裝mysql-devel包操作,命令:yum install mysql-devel,但是報了很多包版本衝突和依賴衝突的錯誤,如下:

[[email protected] linzhongquan]# yum -y install mysql-devel
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.cqu.edu.cn
 * extras: mirrors.163.com
 * updates: mirrors.163.com
Resolving Dependencies
--> Running transaction check
---> Package mariadb-devel.x86_64 1:5.5.50-1.el7_2 will be installed
--> Processing Dependency: mariadb-libs(x86-64) = 1:5.5.50-1.el7_2 for package: 1:mariadb-devel-5.5.50-1.el7_2.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 1:mariadb-devel-5.5.50-1.el7_2.x86_64
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.50-1.el7_2 will be installed
Removing mariadb-libs.x86_64 1:5.5.50-1.el7_2 - u due to obsoletes from installed mysql-community-libs-5.7.14-1.el7.x86_64
--> Restarting Dependency Resolution with new changes.
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.50-1.el7_2 will be installed
--> Processing Dependency: mariadb-libs(x86-64) = 1:5.5.50-1.el7_2 for package: 1:mariadb-devel-5.5.50-1.el7_2.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 1:mariadb-devel-5.5.50-1.el7_2.x86_64
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.47-1.el7_2 will be installed
---> Package mariadb-libs.x86_64 1:5.5.50-1.el7_2 will be installed
--> Processing Dependency: mariadb-libs(x86-64) = 1:5.5.50-1.el7_2 for package: 1:mariadb-devel-5.5.50-1.el7_2.x86_64
Removing mariadb-libs.x86_64 1:5.5.47-1.el7_2 - u due to obsoletes from installed mysql-community-libs-5.7.14-1.el7.x86_64
--> Restarting Dependency Resolution with new changes.
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.47-1.el7_2 will be installed
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 1:mariadb-devel-5.5.50-1.el7_2.x86_64
---> Package mariadb-libs.x86_64 1:5.5.50-1.el7_2 will be installed
--> Processing Dependency: mariadb-libs(x86-64) = 1:5.5.50-1.el7_2 for package: 1:mariadb-devel-5.5.50-1.el7_2.x86_64
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.44-2.el7.centos will be installed
---> Package mariadb-libs.x86_64 1:5.5.50-1.el7_2 will be installed
--> Processing Dependency: mariadb-libs(x86-64) = 1:5.5.50-1.el7_2 for package: 1:mariadb-devel-5.5.50-1.el7_2.x86_64
Removing mariadb-libs.x86_64 1:5.5.44-2.el7.centos - u due to obsoletes from installed mysql-community-libs-5.7.14-1.el7.x86_64
--> Restarting Dependency Resolution with new changes.
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.44-2.el7.centos will be installed
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 1:mariadb-devel-5.5.50-1.el7_2.x86_64
---> Package mariadb-libs.x86_64 1:5.5.50-1.el7_2 will be installed
--> Processing Dependency: mariadb-libs(x86-64) = 1:5.5.50-1.el7_2 for package: 1:mariadb-devel-5.5.50-1.el7_2.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 1:mariadb-devel-5.5.50-1.el7_2.x86_64
--> Finished Dependency Resolution
Error: Package: 1:mariadb-devel-5.5.50-1.el7_2.x86_64 (updates)
           Requires: libmysqlclient.so.18()(64bit)
           Available: 1:mariadb-libs-5.5.44-2.el7.centos.x86_64 (base)
               libmysqlclient.so.18()(64bit)
           Available: 1:mariadb-libs-5.5.47-1.el7_2.x86_64 (updates)
               libmysqlclient.so.18()(64bit)
           Available: 1:mariadb-libs-5.5.50-1.el7_2.x86_64 (updates)
               libmysqlclient.so.18()(64bit)
Error: Package: 1:mariadb-devel-5.5.50-1.el7_2.x86_64 (updates)
           Requires: mariadb-libs(x86-64) = 1:5.5.50-1.el7_2
           Available: 1:mariadb-libs-5.5.44-2.el7.centos.x86_64 (base)
               mariadb-libs(x86-64) = 1:5.5.44-2.el7.centos
           Available: 1:mariadb-libs-5.5.47-1.el7_2.x86_64 (updates)
               mariadb-libs(x86-64) = 1:5.5.47-1.el7_2
           Available: 1:mariadb-libs-5.5.50-1.el7_2.i686 (updates)
              ~mariadb-libs(x86-32) = 1:5.5.50-1.el7_2
Error: Package: 1:mariadb-devel-5.5.50-1.el7_2.x86_64 (updates)
           Requires: mariadb-libs(x86-64) = 1:5.5.50-1.el7_2
           Installing: 1:mariadb-libs-5.5.44-2.el7.centos.x86_64 (base)
               mariadb-libs(x86-64) = 1:5.5.44-2.el7.centos
           Available: 1:mariadb-libs-5.5.47-1.el7_2.x86_64 (updates)
               mariadb-libs(x86-64) = 1:5.5.47-1.el7_2
           Available: 1:mariadb-libs-5.5.50-1.el7_2.i686 (updates)
              ~mariadb-libs(x86-32) = 1:5.5.50-1.el7_2
Error: Package: 1:mariadb-devel-5.5.50-1.el7_2.x86_64 (updates)
           Requires: mariadb-libs(x86-64) = 1:5.5.50-1.el7_2
           Available: 1:mariadb-libs-5.5.44-2.el7.centos.x86_64 (base)
               mariadb-libs(x86-64) = 1:5.5.44-2.el7.centos
           Installing: 1:mariadb-libs-5.5.47-1.el7_2.x86_64 (updates)
               mariadb-libs(x86-64) = 1:5.5.47-1.el7_2
           Available: 1:mariadb-libs-5.5.50-1.el7_2.i686 (updates)
              ~mariadb-libs(x86-32) = 1:5.5.50-1.el7_2
 You could try using --skip-broken to work around the problem
** Found 2 pre-existing rpmdb problem(s), 'yum check' output follows:
icedtea-web-1.6.1-4.el7.x86_64 has missing requires of java-1.8.0-openjdk
jline-1.0-8.el7.noarch has missing requires of java >= ('0', '1.5', None)

以上報錯就是我們這次要解決的問題。

原因

    發現上面預設是要安裝mariadb-devel-5.5.50-1.el7_2.x86_64,這才意識到,之前的mysql是通過編譯的方式安裝,可能是沒有mysql的yum源,然後去/etc/yum.repos.d/路徑下面去看,發現確實是沒有mysql的yum源。如下:

[[email protected] linzhongquan]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# ls
CentOS-Base.repo  CentOS-CR.repo  CentOS-Debuginfo.repo  CentOS-fasttrack.repo  CentOS-Media.repo  CentOS-Sources.repo  CentOS-Vault.repo

所以,安裝mysql-devel報錯的原因應該就是缺少mysql的yum源。

解決方法

1、下載對應版本mysql的yum源的rpm包

wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm

2、安裝rpm包

rpm -ivh mysql57-community-release-el7-8.noarch.rpm

此時,/etc/yum.repos.d/路徑下面會多出兩個檔案:mysql-community.repo、mysql-community-resource.repo。

3、安裝mysql-devel包,命令:yum install mysql-devel,安裝完成!