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,但是报了很多包版本冲突和依赖冲突的错误,如下:

[root@localhost 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源。如下:

[root@localhost linzhongquan]# cd /etc/yum.repos.d/
[root@localhost 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,安装完成!

 

参考:https://my.oschina.net/liuyuantao/blog/746537

你可能感兴趣的:(python实践学习)