点击(此处)折叠或打开
- #安装mysql-server
- #apt-get install mysql-server
- #安装python-mysqldb
- #apt-get install python-mysqldb
- #python
- Python 2.7.12 (default, Dec 4 2017, 14:50:18)
- [GCC 5.4.0 20160609] on linux2
- Type "help", "copyright", "credits" or "license" for more information.
- >>> import MySQLdb
- ...
ImportError: this is MySQLdb version (1, 2, 5, 'final', 1), but _mysql is version (1, 3, 7, 'final', 1)
#apt-get安装的MySQLdb和mysql版本不一致。
#将python-mysqldb卸载
#apt-get remove --purge python-mysqldb
#用pip重新安装
#pip install mysql-python
手动安装MySQL_python-1.2.5
点击(此处)折叠或打开
- #wget https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip
- #unzip MySQL-python-1.2.5.zip
- #cd MySQL-python-1.2.5
- #python setup.py build
- #报错如下:
- sh: 1: mysql_config: not found
- Traceback (most recent call last):
- File "setup.py", line 17, in <module>
- metadata, options = get_config()
- File "/home/ubuntu/MySQL-python-1.2.5/setup_posix.py", line 43, in get_config
- libs = mysql_config("libs_r")
- File "/home/ubuntu/MySQL-python-1.2.5/setup_posix.py", line 25, in mysql_config
- raise EnvironmentError("%s not found" % (mysql_config.path,))
- EnvironmentError: mysql_config not found
- # apt-get install libmysqlclient-dev
- # python setup.py build
- running build
- running build_py
- creating build
- creating build/lib.linux-x86_64-2.7
- copying _mysql_exceptions.py -> build/lib.linux-x86_64-2.7
- creating build/lib.linux-x86_64-2.7/MySQLdb
- copying MySQLdb/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb
- copying MySQLdb/converters.py -> build/lib.linux-x86_64-2.7/MySQLdb
- copying MySQLdb/connections.py -> build/lib.linux-x86_64-2.7/MySQLdb
- copying MySQLdb/cursors.py -> build/lib.linux-x86_64-2.7/MySQLdb
- copying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdb
- copying MySQLdb/times.py -> build/lib.linux-x86_64-2.7/MySQLdb
- creating build/lib.linux-x86_64-2.7/MySQLdb/constants
- copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
- copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
- copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
- copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
- copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
- copying MySQLdb/constants/REFRESH.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
- copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
- running build_ext
- building '_mysql' extension
- creating build/temp.linux-x86_64-2.7
- x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=fat-security -fPIC -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/include/mysql -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o
- x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypesdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wl,-Bsymbolic-functions -Wl,-z,relro -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protectstrong -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/_mysql.o -L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -lm -lrt -ldl -o build/lib.linux-x86_64-2.7/_ml.so
- # python setup.py install
- running install
- running bdist_egg
- running egg_info
- writing MySQL_python.egg-info/PKG-INFO
- writing top-level names to MySQL_python.egg-info/top_level.txt
- writing dependency_links to MySQL_python.egg-info/dependency_links.txt
- reading 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/egg
- running install_lib
- running build_py
- copying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdb
- running build_ext
- creating build/bdist.linux-x86_64
- creating build/bdist.linux-x86_64/egg
- creating build/bdist.linux-x86_64/egg/MySQLdb
- copying build/lib.linux-x86_64-2.7/MySQLdb/converters.py -> build/bdist.linux-x86_64/egg/MySQLdb
- copying build/lib.linux-x86_64-2.7/MySQLdb/cursors.py -> build/bdist.linux-x86_64/egg/MySQLdb
- copying build/lib.linux-x86_64-2.7/MySQLdb/__init__.py -> build/bdist.linux-x86_64/egg/MySQLdb
- copying build/lib.linux-x86_64-2.7/MySQLdb/release.py -> build/bdist.linux-x86_64/egg/MySQLdb
- copying build/lib.linux-x86_64-2.7/MySQLdb/connections.py -> build/bdist.linux-x86_64/egg/MySQLdb
- creating build/bdist.linux-x86_64/egg/MySQLdb/constants
- copying build/lib.linux-x86_64-2.7/MySQLdb/constants/FIELD_TYPE.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
- copying build/lib.linux-x86_64-2.7/MySQLdb/constants/__init__.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
- copying build/lib.linux-x86_64-2.7/MySQLdb/constants/REFRESH.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
- copying build/lib.linux-x86_64-2.7/MySQLdb/constants/CR.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
- copying build/lib.linux-x86_64-2.7/MySQLdb/constants/CLIENT.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
- copying build/lib.linux-x86_64-2.7/MySQLdb/constants/ER.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
- copying build/lib.linux-x86_64-2.7/MySQLdb/constants/FLAG.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
- copying build/lib.linux-x86_64-2.7/MySQLdb/times.py -> build/bdist.linux-x86_64/egg/MySQLdb
- copying build/lib.linux-x86_64-2.7/_mysql_exceptions.py -> build/bdist.linux-x86_64/egg
- copying build/lib.linux-x86_64-2.7/_mysql.so -> build/bdist.linux-x86_64/egg
- byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/converters.py to converters.pyc
- byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/cursors.py to cursors.pyc
- byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/__init__.py to __init__.pyc
- byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/release.py to release.pyc
- byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/connections.py to connections.pyc
- byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/FIELD_TYPE.py to FIELD_TYPE.pyc
- byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/__init__.py to __init__.pyc
- byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/REFRESH.py to REFRESH.pyc
- byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/CR.py to CR.pyc
- byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/CLIENT.py to CLIENT.pyc
- byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/ER.py to ER.pyc
- byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/FLAG.py to FLAG.pyc
- byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/times.py to times.pyc
- byte-compiling build/bdist.linux-x86_64/egg/_mysql_exceptions.py to _mysql_exceptions.pyc
- creating stub loader for _mysql.so
- byte-compiling build/bdist.linux-x86_64/egg/_mysql.py to _mysql.pyc
- creating build/bdist.linux-x86_64/egg/EGG-INFO
- copying MySQL_python.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
- copying MySQL_python.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
- copying MySQL_python.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
- copying MySQL_python.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
- writing build/bdist.linux-x86_64/egg/EGG-INFO/native_libs.txt
- zip_safe flag not set; analyzing archive contents...
- creating dist
- creating 'dist/MySQL_python-1.2.5-py2.7-linux-x86_64.egg' and adding 'build/bdist.linux-x86_64/egg' to it
- removing 'build/bdist.linux-x86_64/egg' (and everything under it)
- Processing MySQL_python-1.2.5-py2.7-linux-x86_64.egg
- Copying MySQL_python-1.2.5-py2.7-linux-x86_64.egg to /usr/local/lib/python2.7/dist-packages
- Adding MySQL-python 1.2.5 to easy-install.pth file
- Installed /usr/local/lib/python2.7/dist-packages/MySQL_python-1.2.5-py2.7-linux-x86_64.egg
- Processing dependencies for MySQL-python==1.2.5
- Finished processing dependencies for MySQL-python==1.2.5