Fedora環境Python訪問MySQL安裝MySQLdb

來源:互聯網
上載者:User

本人是Fedora下的,如果是其他的只是在命令列上略有區別而已。


1、安裝資料庫驅動適配器

http://sourceforge.net/projects/mysql-python/

2、解壓安裝,解壓以後,安裝的時候可能會出現問題。

  1. python setup.py install    (一般情況基本會失敗)  
因為是用setuptools安裝的,所以先安裝 setuptools
  1. python ez_setup.py  
這樣setuptools安裝以後,在來執行上面的語句
  1. python setup.py install  
可能會報一個錯誤,就是 _mysql.c 的問題
  1. building '_mysql' extension  
  2. gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i686 -mtune=atom -fasynchronous-unwind-tables -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i686 -mtune=atom -fasynchronous-unwind-tables -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 -I/usr/include/mysql -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-i686-2.7/_mysql.o -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -fasynchronous-unwind-tables -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv -fPIC -fPIC -g -static-libgcc -fno-omit-frame-pointer -fno-strict-aliasing -DMY_PTHREAD_FASTMUTEX=1  
  3. In file included from /usr/include/mysql/my_config.h:16:0,  
  4.                  from _mysql.c:36:  
此時只要安裝mysql-dev,python-dev即可
  1. yum install mysql-dev*  
  2. yum install python-dev*  

再運行試試,我是成功了,你呢?

  1. python setup.py install  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.