首页 > 代码库 > python mysql

python mysql

一、centos 安装mysql

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

2) 解压缩
$unzip MySQL-python-1.2.5.zip
$cd MySQL-python-1.2.5

3)修改mysql配置路径, 否则提示找不到配置文件
修改 setup_posix.py 文件
vim setup_posix.py

修改 27行 mysql_config.path = "mysql_config"
mysql_config.path = "/usr/local/mysql/bin/mysql_config"

4)安装python MySQLdb
$sudo python setup.py install

下载完mysqldb后,进入其目录,运行python setup.py install会报出一大堆错,原因是很多依赖库都没有安装,我们需要在这之前运行:

yum install gcc Python-devel MySQL-devel -y 
然后再运行setup就没问题了。

 

5)测试

$ python
Python 2.7.11 (default, Aug  6 2016, 01:58:12) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>> 

 

python mysql