mysql-python的安装

安装过程遇到很多问题,备忘:

1、下载mysql-python

官网地址: http://sourceforge.net/projects/mysql-python/

# cd /usr/local

# wget http://nchc.dl.sourceforge.net/sourceforge/mysql-python/MySQL-python-1.2.2.tar.gz

2、解压

# tar -zxvf MySQL-python-1.2.2.tar.gz

# cd MySQL-python-1.2.2

3、在安装前要做下面几步

     a、修改setup_posix.py中的mysql_config.path为你mysql安装目录的mysql_config路径

     b、修改site.cfg中的threadsafe = False,mysql_config = /usr/local/mysql/bin/mysql_config

     c、执行命令:(注意这个地方,三条命令都执行)

          # export LD_LIBRARY_PATH=/usr/local/mysql/lib/mysql

          # ln -s /usr/local/mysql/lib/mysql/libmysqlclient.so /usr/lib/libmysqlclient.so.14

          # ldconfig (这个重要)

          否则后面会报错ImportError: libmysqlclient.so.14: cannot open shared object file

4、build和install

# python setup.py build
# python setup.py install

5、使用

# python

# >>> import MySSQLdb

如果报错

/usr/lib/python2.3/site-packages/MySQL_python-1.2.2-py2.3-linux-i686.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/lib/python2.3/site-packages/MySQL_python-1.2.2-py2.3-linux-i686.egg/_mysql.pyc, but /usr/local/src/MySQL-python-1.2.2 is being added to sys.path

原因是,install后MySQLdb模块已经被放到python的site-pachages目录中;但我在当前目录也存在相同的模块,所以可能会重复导入。只要切换到其他目录运行python就可以了。

你可能感兴趣的:(python)