linux 安装 MySQL ------------python 操作mysql

python 操作 MySQL

要想使python可以操作mysql 就需要MySQL-python驱动,它是python 操作mysql必不可少的模块。

下载地址:Linux平台访问:https://pypi.python.org/pypi/MySQL-python

下载MySQL-python-1.2.5.zip 文件之后直接解压。进入MySQL-python-1.2.5目录:

在终端中打开运行如下命令:

sudo python setup.py install

此时如果出现如下错误:

Complete output from command python setup.py egg_info:
    sh: 1: mysql_config: not found
    Traceback (most recent call last):
      File "", line 1, in 
      File "/tmp/pip-build-0PWaDX/mysql-python/setup.py", line 17, in 
        metadata, options = get_config()
      File "/tmp/pip-build-0PWaDX/mysql-python/setup_posix.py", line 43, in get_config
        libs = mysql_config("libs_r")
      File "/tmp/pip-build-0PWaDX/mysql-python/setup_posix.py", line 25, in mysql_config
        raise EnvironmentError("%s not found" % (mysql_config.path,))
    EnvironmentError: mysql_config not found

这是因为ubuntu中mysql_config不在mysql-server中,我们还需要安装libmysqlclient-dev,mysql_config在这个里面

sudo apt install libmysqlclient-dev
再次执行上一个命令。

检测一下:

python 

>>> import MySQLdb

不出现错误说明完成安装




你可能感兴趣的:(linux 安装 MySQL ------------python 操作mysql)