mysql資料庫連線(MySQLdb)

pathfinder_cui發表於2015-07-20
環境CentOS release 6.5(final)
mysql 5.6.22-log

準備工作:

yum install python-devel
wget /> wget />
安裝
setuptools

python setup.py build

python setup.py install


安裝
MySQL-python

先查詢mysql_config的位置,使用命令:

      find / -name mysql_config

然後我們獲取到它的路徑,我的是:/usr/bin/mysql_config,然後修改MySQL-python-1.2.3目錄下的site.cfg檔案,去掉mysql_config=XXX這行前面的#並修改...

python setup.py build

python setup.py install


最後程式python
編輯器
python

import sys
import MySQLdb

報錯:
>>> import MySQLdb
/usr/local/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-linux-x86_64.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /usr/local/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-linux-x86_64.egg/_mysql.pyc, but /soft/MySQL-python-1.2.3 is being added to sys.path
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "MySQLdb/__init__.py", line 19, in <module>
    import _mysql
  File "build/bdist.linux-x86_64/egg/_mysql.py", line 7, in <module>
  File "build/bdist.linux-x86_64/egg/_mysql.py", line 6, in __bootstrap__
ImportError: libmysqlclient.so.18: cannot open shared object file: No such file or directory

解決方法: 
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18

如果是64系統則:  
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18



來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29620572/viewspace-1742026/,如需轉載,請註明出處,否則將追究法律責任。

相關文章