Centos7 pip 安装MySQLdb(mysql-python)出错

租了个阿里云的Centos7的ECS,需要使用pip安装MySQLdb模块。也就是mysql-python模块。

但是遇到问题

Collecting mysql-python
  Downloading https://pypi.doubanio.com/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip (108kB)
    100% |████████████████████████████████| 112kB 1.0MB/s 
    Complete output from command python setup.py egg_info:
    sh: mysql_config: 未找到命令
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-ulw6QD/mysql-python/setup.py", line 17, in <module>
        metadata, options = get_config()
      File "setup_posix.py", line 43, in get_config
        libs = mysql_config("libs_r")
      File "setup_posix.py", line 25, in mysql_config
        raise EnvironmentError("%s not found" % (mysql_config.path,))
    EnvironmentError: mysql_config not found
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-ulw6QD/mysql-python/

  

找不到mysql_config文件。

网上找了一下出错的原因,原因是没有安装mysql-devel。

用yum安装

sudo yum install mysql-devel

  

出现问题:

已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 mariadb-devel.x86_64.1.5.5.52-1.el7 将被 安装
--> 正在处理依赖关系 mariadb-libs(x86-64) = 1:5.5.52-1.el7,它被软件包 1:mariadb-devel-5.5.52-1.el7.x86_64 需要
--> 正在处理依赖关系 openssl-devel(x86-64),它被软件包 1:mariadb-devel-5.5.52-1.el7.x86_64 需要
--> 正在处理依赖关系 libmysqlclient.so.18()(64bit),它被软件包 1:mariadb-devel-5.5.52-1.el7.x86_64 需要
--> 正在检查事务
---> 软件包 mariadb-libs.x86_64.1.5.5.52-1.el7 将被 安装
---> 软件包 openssl-devel.x86_64.1.1.0.1e-60.el7_3.1 将被 安装
--> 正在处理依赖关系 zlib-devel(x86-64),它被软件包 1:openssl-devel-1.0.1e-60.el7_3.1.x86_64 需要
--> 正在处理依赖关系 krb5-devel(x86-64),它被软件包 1:openssl-devel-1.0.1e-60.el7_3.1.x86_64 需要
--> 正在检查事务
---> 软件包 krb5-devel.x86_64.0.1.14.1-27.el7_3 将被 安装
--> 正在处理依赖关系 libkadm5(x86-64) = 1.14.1-27.el7_3,它被软件包 krb5-devel-1.14.1-27.el7_3.x86_64 需要
--> 正在处理依赖关系 libverto-devel,它被软件包 krb5-devel-1.14.1-27.el7_3.x86_64 需要
--> 正在处理依赖关系 libselinux-devel,它被软件包 krb5-devel-1.14.1-27.el7_3.x86_64 需要
--> 正在处理依赖关系 libcom_err-devel,它被软件包 krb5-devel-1.14.1-27.el7_3.x86_64 需要
--> 正在处理依赖关系 keyutils-libs-devel,它被软件包 krb5-devel-1.14.1-27.el7_3.x86_64 需要
---> 软件包 zlib-devel.x86_64.0.1.2.7-17.el7 将被 安装
--> 正在检查事务
---> 软件包 keyutils-libs-devel.x86_64.0.1.5.8-3.el7 将被 安装
---> 软件包 libcom_err-devel.x86_64.0.1.42.9-9.el7 将被 安装
---> 软件包 libkadm5.x86_64.0.1.14.1-27.el7_3 将被 安装
---> 软件包 libselinux-devel.x86_64.0.2.5-6.el7 将被 安装
--> 正在处理依赖关系 libsepol-devel(x86-64) >= 2.5-6,它被软件包 libselinux-devel-2.5-6.el7.x86_64 需要
--> 正在处理依赖关系 pkgconfig(libsepol),它被软件包 libselinux-devel-2.5-6.el7.x86_64 需要
--> 正在处理依赖关系 pkgconfig(libpcre),它被软件包 libselinux-devel-2.5-6.el7.x86_64 需要
---> 软件包 libverto-devel.x86_64.0.0.2.5-4.el7 将被 安装
--> 正在检查事务
---> 软件包 libsepol-devel.x86_64.0.2.5-6.el7 将被 安装
---> 软件包 pcre-devel.x86_64.0.8.32-15.el7_2.1 将被 安装
Removing mariadb-libs.x86_64 1:5.5.52-1.el7 - u due to obsoletes from installed mysql-community-libs-5.7.16-1.el7.x86_64
--> 正在使用新的信息重新解决依赖关系
--> 正在检查事务
---> 软件包 mariadb-libs.x86_64.1.5.5.52-1.el7 将被 安装
--> 正在处理依赖关系 mariadb-libs(x86-64) = 1:5.5.52-1.el7,它被软件包 1:mariadb-devel-5.5.52-1.el7.x86_64 需要
--> 正在处理依赖关系 libmysqlclient.so.18()(64bit),它被软件包 1:mariadb-devel-5.5.52-1.el7.x86_64 需要
--> 解决依赖关系完成
错误:软件包:1:mariadb-devel-5.5.52-1.el7.x86_64 (base)
          需要:mariadb-libs(x86-64) = 1:5.5.52-1.el7
错误:软件包:1:mariadb-devel-5.5.52-1.el7.x86_64 (base)
          需要:libmysqlclient.so.18()(64bit)
 您可以尝试添加 --skip-broken 选项来解决该问题
 您可以尝试执行:rpm -Va --nofiles --nodigest

  

可以看到安装的其实是mariadb。这是mysql的一个分支,原因好像是Centos7安装mysql需要付费(不太清楚)。

我的解决办法是:

去mysql官网下载文件,下载地址 http://dev.mysql.com/downloads/mysql/ 

按图选择版本

 

选择第一个下载并解压。使用WinSCP登陆到虚拟机,将rpm文件拷贝到centOS 下的/usr/local/mysql下(来自http://blog.csdn.net/f7anty/article/details/51959463)

其实阿里云在/home目录下已经下载好了这些文件

[kicc@Dmc mebeforeU]$ ls /home
kicc                                                     mysql-community-libs-compat-5.7.16-1.el7.x86_64.rpm
mysql-community-client-5.7.16-1.el7.x86_64.rpm           mysql-community-minimal-debuginfo-5.7.16-1.el7.x86_64.rpm
mysql-community-common-5.7.16-1.el7.x86_64.rpm           mysql-community-server-5.7.16-1.el7.x86_64.rpm
mysql-community-devel-5.7.16-1.el7.x86_64.rpm            mysql-community-server-minimal-5.7.16-1.el7.x86_64.rpm
mysql-community-embedded-5.7.16-1.el7.x86_64.rpm         mysql-community-test-5.7.16-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.16-1.el7.x86_64.rpm  tomcat
mysql-community-embedded-devel-5.7.16-1.el7.x86_64.rpm   uftp
mysql-community-libs-5.7.16-1.el7.x86_64.rpm

  

因此只要用rpm安装即可:(按序)

[kicc@Dmc home]$ sudo rpm -ivh mysql-community-common-5.7.16-1.el7.x86_64.rpm
[kicc@Dmc home]$ sudo rpm -ivh mysql-community-libs-5.7.16-1.el7.x86_64.rpm
[kicc@Dmc home]$ sudo rpm -ivh mysql-community-devel-5.7.16-1.el7.x86_64.rpm
[kicc@Dmc home]$ sudo rpm -ivh mysql-community-client-5.7.16-1.el7.x86_64.rpm
[kicc@Dmc home]$ sudo rpm -ivh mysql-community-server-5.7.16-1.el7.x86_64.rpm

  

我的服务器上除了

mysql-community-devel-5.7.16-1.el7.x86_64.rpm,其他都已经安装。这也就是mysql-devel始终无法安装的原因。

安装完之后,就是安装了mysql-devel。此时再安装mysql-python。pip install mysql-python

>pip install mysql-python
Collecting mysql-python
  Downloading https://pypi.doubanio.com/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip (108kB)
    100% |████████████████████████████████| 112kB 290kB/s 
Building wheels for collected packages: mysql-python
  Running setup.py bdist_wheel for mysql-python ... done
  Stored in directory: /home/kicc/.cache/pip/wheels/5a/7c/08/462460b38b37adfc478e73bbf2e4ae809d57384f567ded548f
Successfully built mysql-python
Installing collected packages: mysql-python
Successfully installed mysql-python-1.2.5

  

顺便提一句mysql的密码如何重置:

修改/ect/ 下的my.cnf文件

sudo vi /etc/my.cnf

 

插入

skip-grant-tables

  

保存文件。语句的作用是不需要密码就能够登录mysql

> mysql

登录后,use  mysql,输入:

update  user  set  password  =  password("147258")where  user='root';
或者
update  user  set  password  =  authentication_string("147258")where  user='root' and Host='localhost';

  

再将

skip-grant-tables 注释掉即可。

这样就重置了mysql的密码,可以使用新密码登录mysql。

 

结束。之前在utuntu上也出过这个问题,解决起来会容易一些。有空在写一下吧...

  

 

posted @ 2017-06-28 15:14  悟空的爸爸  阅读(1293)  评论(0编辑  收藏  举报