Python 牵手 MySQL

原创 2017年08月18日 21:08:39
安装python
 wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2rc2.tgz
 tar -xvf Python-3.6.2rc2.tgz
 cd Python-3.6.2rc2
 make
 make install
 mv /usr/bin/python /usr/bin/python2.7.5.old
 ln -s /usr/local/python3.6.2/bin/python3.6 /usr/bin/python
 ln -s /usr/local/python3.6.2/bin/python3.6 /usr/bin/python3

 修改yum的python
 vim /usr/bin/yum
 #!/usr/bin/python修改成 #!/usr/bin/python2.7.5.old
 这是因为yum默认使用的python版本是2.7.5,到哪是现在的python版本是3.6,故会出现上述问题,只需要该一下yum的默认python配置版本就行了:



 下载python-mysql
 https://pypi.python.org/pypi/MySQL-python/1.2.5
 下载wget https://pypi.python.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip#md5=654f75b302db6ed8dc5a898c625e030c
 unzip MySQL-python-1.2.5.zip

 wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
tar zxvf setuptools-0.6c11.tar.gz
cd setuptools-0.6c11
python setup.py build
python setup.py install



yum install -y MySQL-python

报错:
[root@huayuan] /home/laobanzhang/software/MySQL-python-1.2.5$ python setup.py build
sh: mysql_config: command not found
Traceback (most recent call last):
  File "setup.py", line 17, in <module>
    metadata, options = get_config()
  File "/home/laobanzhang/software/MySQL-python-1.2.5/setup_posix.py", line 43, in get_config
    libs = mysql_config("libs_r")
  File "/home/laobanzhang/software/MySQL-python-1.2.5/setup_posix.py", line 25, in mysql_config
    raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
[root@huayuan] /home/laobanzhang/software/MySQL-python-1.2.5$ 

解决:
find / -name python;找到python路径/usr/bin/python,所以在/etc/profile里面末尾配置python路径

export PATH=/usr/bin/:$PATH

报错:
[root@huayuan] /home/laobanzhang/software/MySQL-python-1.2.5$ python setup.py build
running build
running build_py
copying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdb
running build_ext
building '_mysql' extension
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/include/mysql -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o
_mysql.c:29:20: fatal error: Python.h: No such file or directory
 #include "Python.h"
                    ^
compilation terminated.
error: command 'gcc' failed with exit status 1
[root@huayuan]  


解决: yum -y install mysql-devel libxml2 libxml2-dev libxslt* zlib gcc openssl

[root@huayuan] /home/laobanzhang/software/MySQL-python-1.2.5$ python setup.py build
running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
copying _mysql_exceptions.py -> build/lib.linux-x86_64-2.7
creating build/lib.linux-x86_64-2.7/MySQLdb
copying MySQLdb/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb
copying MySQLdb/converters.py -> build/lib.linux-x86_64-2.7/MySQLdb
copying MySQLdb/connections.py -> build/lib.linux-x86_64-2.7/MySQLdb
copying MySQLdb/cursors.py -> build/lib.linux-x86_64-2.7/MySQLdb
copying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdb
copying MySQLdb/times.py -> build/lib.linux-x86_64-2.7/MySQLdb
creating build/lib.linux-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/REFRESH.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
running build_ext
building '_mysql' extension
creating build/temp.linux-x86_64-2.7
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/include/mysql -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o
_mysql.c:29:20: fatal error: Python.h: No such file or directory
 #include "Python.h"
                    ^
compilation terminated.
error: command 'gcc' failed with exit status 1

解决:yum install python-devel -y

再执行命令:
python setup.py build
python setup.py install


测试是否能链接
[root@huayuan] /home/laobanzhang/software/MySQL-python-1.2.5$ python
Python 2.7.5 (default, Nov  6 2016, 00:28:07) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
/usr/lib64/python2.7/site-packages/MySQL_python-1.2.5-py2.7-linux-x86_64.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/lib64/python2.7/site-packages/MySQL_python-1.2.5-py2.7-linux-x86_64.egg/_mysql.pyc, but /home/laobanzhang/software/MySQL-python-1.2.5 is being added to sys.path
>>> 
版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

python学习---3(DBUtils.PooledDB)

#-*- coding: utf-8 -*- """ 数据库管理类 """ import MySQLdb from DBUtils.PooledDB import PooledDB #自定义的配置文件...

牛人比普通人强在哪里?

-- 1世间所谓的伟大,其本质不过是执着,但是执着的另一面,却是顽固。--> 祭北宋老王网络盛传的牛人,其本质不过是坚持,坚持到比他厉害的人都走了,于是山中无老虎、他称大王他就是最牛的,于是他就是牛人...
  • mchdba
  • mchdba
  • 2016-11-04 20:51
  • 1369

RDS 在线DDL诡异报错ERROR 1062 (23000): Duplicate entry

RDS上执行报错如下:MySQL [ad_billing]> ALTER TABLE ad_spending ADD COLUMN impr bigint(20) NOT NULL DEFAULT 0...

JAVA面试问题及答案(上)

1. 面向对象和面向过程的区别 面向过程  优点:性能比面向对象高,因为类调用时需要实例化,开销比较大,比较消耗资源;比如单片机、嵌入式开发、Linux/Unix等一般采用面向过程开发,性能是最重...
  • ls5718
  • ls5718
  • 2016-08-30 16:25
  • 1031

多线程死锁的产生以及如何避免死锁

一、死锁的定义 多线程以及多进程改善了系统资源的利用率并提高了系统 的处理能力。然而,并发执行也带来了新的问题——死锁。所谓死锁是指多个线程因竞争资源而造成的一种僵局(互相等待),若无外力作用,这些进...
  • ls5718
  • ls5718
  • 2016-07-13 11:07
  • 13030

Google搜索技巧

目前, Internet 上有两种搜索引擎. 一种是The Searchable Subject Index,索引式搜索. 这种搜索引擎只搜索站点的Title和Meta描述信息. 而无法搜索个人主页,...

牵手小吉界面

  • 2017-07-22 11:18
  • 5.90MB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)