MySQLdb-python安裝

來源:互聯網
上載者:User

標籤:style   blog   http   io   ar   color   os   使用   sp   

安裝很簡單,步驟如下:

前期:yum -y install python-setuptools,或者自己網上找源碼包安裝

1. 下載安裝包:

 #wget  https://pypi.python.org/packages/source/M/MySQL-python/MySQL-python-1.2.5.zip --no-check-certificate

#unzip  MySQL-python-1.2.5.zip

#cd MySQL-python-1.2.5

#python setup.py build

[[email protected] MySQL-python-1.2.5]# python setup.py  buildrunning buildrunning build_pycreating buildcreating build/lib.linux-x86_64-2.6copying _mysql_exceptions.py -> build/lib.linux-x86_64-2.6creating build/lib.linux-x86_64-2.6/MySQLdbcopying MySQLdb/__init__.py -> build/lib.linux-x86_64-2.6/MySQLdbcopying MySQLdb/converters.py -> build/lib.linux-x86_64-2.6/MySQLdbcopying MySQLdb/connections.py -> build/lib.linux-x86_64-2.6/MySQLdbcopying MySQLdb/cursors.py -> build/lib.linux-x86_64-2.6/MySQLdbcopying MySQLdb/release.py -> build/lib.linux-x86_64-2.6/MySQLdbcopying MySQLdb/times.py -> build/lib.linux-x86_64-2.6/MySQLdbcreating build/lib.linux-x86_64-2.6/MySQLdb/constantscopying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-2.6/MySQLdb/constantscopying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-2.6/MySQLdb/constantscopying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-2.6/MySQLdb/constantscopying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-2.6/MySQLdb/constantscopying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-2.6/MySQLdb/constantscopying MySQLdb/constants/REFRESH.py -> build/lib.linux-x86_64-2.6/MySQLdb/constantscopying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-2.6/MySQLdb/constantsrunning build_extbuilding ‘_mysql‘ extensioncreating build/temp.linux-x86_64-2.6gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Dversion_info=(1,2,5,‘final‘,1) -D__version__=1.2.5 -I/usr/include/mysql -I/usr/include/python2.6 -c _mysql.c -o build/temp.linux-x86_64-2.6/_mysql.o -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv -fPIC -DUNIV_LINUX -DUNIV_LINUXIn file included from /usr/include/mysql/my_config.h:14,                 from _mysql.c:44:/usr/include/mysql/my_config_x86_64.h:1082:1: warning: "HAVE_WCSCOLL" redefinedIn file included from /usr/include/python2.6/pyconfig.h:6,                 from /usr/include/python2.6/Python.h:8,                 from _mysql.c:29:/usr/include/python2.6/pyconfig-64.h:808:1: warning: this is the location of the previous definitiongcc -pthread -shared build/temp.linux-x86_64-2.6/_mysql.o -L/usr/lib64/mysql -L/usr/lib64 -lmysqlclient_r -lz -lpthread -lcrypt -lnsl -lm -lpthread -lssl -lcrypto -lpython2.6 -o build/lib.linux-x86_64-2.6/_mysql.so
View Code

#python setup.py install

[[email protected]]# python setup.py installrunning installrunning bdist_eggrunning egg_infowriting MySQL_python.egg-info/PKG-INFOwriting top-level names to MySQL_python.egg-info/top_level.txtwriting dependency_links to MySQL_python.egg-info/dependency_links.txtreading manifest file ‘MySQL_python.egg-info/SOURCES.txt‘reading manifest template ‘MANIFEST.in‘writing manifest file ‘MySQL_python.egg-info/SOURCES.txt‘installing library code to build/bdist.linux-x86_64/eggrunning install_librunning build_pycopying MySQLdb/release.py -> build/lib.linux-x86_64-2.6/MySQLdbrunning build_extcreating build/bdist.linux-x86_64creating build/bdist.linux-x86_64/eggcreating build/bdist.linux-x86_64/egg/MySQLdbcopying build/lib.linux-x86_64-2.6/MySQLdb/times.py -> build/bdist.linux-x86_64/egg/MySQLdbcreating build/bdist.linux-x86_64/egg/MySQLdb/constantscopying build/lib.linux-x86_64-2.6/MySQLdb/constants/__init__.py -> build/bdist.linux-x86_64/egg/MySQLdb/constantscopying build/lib.linux-x86_64-2.6/MySQLdb/constants/REFRESH.py -> build/bdist.linux-x86_64/egg/MySQLdb/constantscopying build/lib.linux-x86_64-2.6/MySQLdb/constants/CR.py -> build/bdist.linux-x86_64/egg/MySQLdb/constantscopying build/lib.linux-x86_64-2.6/MySQLdb/constants/CLIENT.py -> build/bdist.linux-x86_64/egg/MySQLdb/constantscopying build/lib.linux-x86_64-2.6/MySQLdb/constants/FLAG.py -> build/bdist.linux-x86_64/egg/MySQLdb/constantscopying build/lib.linux-x86_64-2.6/MySQLdb/constants/ER.py -> build/bdist.linux-x86_64/egg/MySQLdb/constantscopying build/lib.linux-x86_64-2.6/MySQLdb/constants/FIELD_TYPE.py -> build/bdist.linux-x86_64/egg/MySQLdb/constantscopying build/lib.linux-x86_64-2.6/MySQLdb/cursors.py -> build/bdist.linux-x86_64/egg/MySQLdbcopying build/lib.linux-x86_64-2.6/MySQLdb/converters.py -> build/bdist.linux-x86_64/egg/MySQLdbcopying build/lib.linux-x86_64-2.6/MySQLdb/__init__.py -> build/bdist.linux-x86_64/egg/MySQLdbcopying build/lib.linux-x86_64-2.6/MySQLdb/connections.py -> build/bdist.linux-x86_64/egg/MySQLdbcopying build/lib.linux-x86_64-2.6/MySQLdb/release.py -> build/bdist.linux-x86_64/egg/MySQLdbcopying build/lib.linux-x86_64-2.6/_mysql.so -> build/bdist.linux-x86_64/eggcopying build/lib.linux-x86_64-2.6/_mysql_exceptions.py -> build/bdist.linux-x86_64/eggbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/times.py to times.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/__init__.py to __init__.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/REFRESH.py to REFRESH.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/CR.py to CR.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/CLIENT.py to CLIENT.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/FLAG.py to FLAG.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/ER.py to ER.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/FIELD_TYPE.py to FIELD_TYPE.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/cursors.py to cursors.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/converters.py to converters.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/__init__.py to __init__.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/connections.py to connections.pycbyte-compiling build/bdist.linux-x86_64/egg/MySQLdb/release.py to release.pycbyte-compiling build/bdist.linux-x86_64/egg/_mysql_exceptions.py to _mysql_exceptions.pyccreating stub loader for _mysql.sobyte-compiling build/bdist.linux-x86_64/egg/_mysql.py to _mysql.pyccreating build/bdist.linux-x86_64/egg/EGG-INFOcopying MySQL_python.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFOcopying MySQL_python.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFOcopying MySQL_python.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFOcopying MySQL_python.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFOwriting build/bdist.linux-x86_64/egg/EGG-INFO/native_libs.txtzip_safe flag not set; analyzing archive contents...creating distcreating ‘dist/MySQL_python-1.2.5-py2.6-linux-x86_64.egg‘ and adding ‘build/bdist.linux-x86_64/egg‘ to itremoving ‘build/bdist.linux-x86_64/egg‘ (and everything under it)Processing MySQL_python-1.2.5-py2.6-linux-x86_64.eggcreating /usr/lib64/python2.6/site-packages/MySQL_python-1.2.5-py2.6-linux-x86_64.eggExtracting MySQL_python-1.2.5-py2.6-linux-x86_64.egg to /usr/lib64/python2.6/site-packagesAdding MySQL-python 1.2.5 to easy-install.pth fileInstalled /usr/lib64/python2.6/site-packages/MySQL_python-1.2.5-py2.6-linux-x86_64.eggProcessing dependencies for MySQL-python==1.2.5Finished processing dependencies for MySQL-python==1.2.5
View Code

測試:

[[email protected] MySQL-python-1.2.5]# pythonPython 2.6.6 (r266:84292, Jan 22 2014, 09:42:36) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import MySQLdb>>> quit()未成功安裝測試時會提示:>>> import mysqldbTraceback (most recent call last):  File "<stdin>", line 1, in <module>ImportError: No module named mysqldb

安裝時遇到的錯誤:

若在執行python setup.py build時報錯報EnvironmentError: mysql_config not found,需要進行如下操作:

1. 使用find / -name mysql_config尋找mysql_config的位置,如/usr/bin/mysql/mysql_config

2. 修改MySQL-python-1.2.5 /site.cfg檔案,去掉mysql_config=XXX注釋,並改成mysql_config=/usr/bin/mysql/mysql_config

3. 如果沒有mysql_config命令,則需要安裝如下包:

yum -y install mysql-server mysql-devel mysql-shared

 

MySQLdb-python安裝

相關文章

聯繫我們

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