Home > Database > Mysql Tutorial > body text

linux下安装MySQLdb模块_MySQL

WBOY
Release: 2016-06-01 13:32:21
Original
889 people have browsed it

bitsCN.com

linux下安装MySQLdb模块

 

1,查看是否已安装MySQLdb模块

   进入python的命令行,输入 import MySQLdb 如果没有报错,证明此模块已经安装,可以跳过以下步骤。

2,下载最新的MySQLdb安装包:

   wget -O python-1.2.3c1.tar.gz  http://cdnetworks-kr-1.dl.sourceforge.net/project/mysql-python/mysql-python-test/1.2.3c1/MySQL-python-1.2.3c1.tar.gz

   tar xzvf python-1.2.3c1.tar.gz  

   cd MySQL-python-1.2.3c1

3,进入用户MySQLdb源码目录,运行 python setup.py build。

    报错:ImportError: No module named setuptools

    解决:安装setuptools

              wget -O setuptools-0.6c8.tar.gz  http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c8.tar.gz

              tar xzvf setuptools-0.6c8.tar.gz

              cd setuptools-0.6c8

              python setup.py build

              sudo python setup.py install

 

    报错:mysql_config not found

    原因:mysql_config命令没有找到。

    解决:

             1)使用whereis mysql命令找到mysql安装目录,假设mysql安装在/usr/local/mysql

             2) 回到MySQLdb源码目录, vi setup_posix.py 或 vimsetup_posix.py打开配置文件,找到mysql_config.path一行,把路径改为mysql安装路径下bin目录,即mysql_config.path ="/usr/local/mysql/bin/mysql_config"。

                   如果MySQL安装在系统默认路径下,mysql_config脚本文件位于"/usr/bin/mysql_config"。(如果没有mysql_config,则需要安装mysql-dev包)

 

    报错: /usr/bin/ld: cannot find -lmysqlclient_r

    解决:

          切换到root用户,执行echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf#请主意这个/etc/ld.so.conf,这个是ld的默认配置文件,视系统不同而不同。/usr/local/mysql/lib/mysql与mysql安装目录相关。

          强制刷新ld的配置文件。使用:ldconfig

          进入mysql的lib目录如/usr/local/mysql/lib/mysql #与mysql安装目录相关。

          如果没有libmysqlclient_r.so 就建立一个软连接 ln -s libmysqlclient.so libmysqlclient_r.so

          退出root,切换到当前用户.

 

    报错: _mysql.c:2810: error: expected declaration specifiers before 'init_mysql'

    解决:安装python-dev,yum install python-devel

 

4,进入用户MySQLdb源码目录,运行

sudo python setup.py install
Copy after login


bitsCN.com
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!