Python中使用MySQL的問題

來源:互聯網
上載者:User

第一步:安裝MySQL-python-1.2.2.tar

python setup.py build
python setup.py intstall

第二步:可能遇到的錯誤

1、libmysqlclient.so.16: cannot open shared object file: No such file or directory

需要安裝新的包mysqlclient16-5.1.30-1.el5.remi.i386

或者通過ln -s設定連結

2、 在build的時候需要按照setuptools-0.6b1-py2.4.egg包

% wget -q http://peak.telecommunity.com/dist/ez_setup.py

% python ez_setup.py
  Downloading http://cheeseshop.python.org/packages/2.4/s/
  setuptools/setuptools-0.6b1-py2.4.egg#md5=b79a8a403e4502fbb85ee3f1941735cb
  Processing setuptools-0.6b1-py2.4.egg
  creating /sw/lib/python2.4/site-packages/setuptools-0.6b1-py2.4.egg
  Extracting setuptools-0.6b1-py2.4.egg to /sw/lib/python2.4/site-packages
  Removing setuptools 0.6a11 from easy-install.pth file
  Adding setuptools 0.6b1 to easy-install.pth file
  Installing easy_install script to /sw/bin
  Installing easy_install-2.4 script to /sw/bin

  Installed /sw/lib/python2.4/site-packages/setuptools-0.6b1-py2.4.egg
  Processing dependencies for setuptools

這個按照需要上網,需要設定網路環境ip地址+DNS。

3  EnvironmentError: mysql_config not found

MySQL-python-1.2.2]# vi setup_posix.py
26 mysql_config.path = "/usr/local/mysql/bin/mysql_config"
將26行改為mysql_config的真是路徑
再次執行python setup.py build;python setup.py install
就OK了

4 /usr/bin/ld: cannot find -lmysqlclient_r
 解決方案一(已經測試通過)

執行以下命令:

echo “/usr/local/mysql/lib/mysql” >> /etc/ld.so.conf(我的環境是CentOS 5)

ldconfig,執行以後還是提示以上錯誤。

———————–

後來看來一下README,原文在下面

——————-

threadsafe
        thread-safe client library (libmysqlclient_r) if True (default);
        otherwise use non-thread-safe (libmysqlclient). You should
        always use the thread-safe library if you have the option;
        otherwise you *may* have problems.

———————————

得知得修改site.cfg,將thread-safe設為false,一切OK!

python setup.py install

解決方案二(沒有測試)A thread-safe client library (libmysqlclient_r) will be created automatically during the compilation of MySQL  if the configure command contains the option "--enable-thread-safe-client".

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.