点击(此处)折叠或打开

  1. #安装mysql-server
  2. #apt-get install mysql-server
  3. #安装python-mysqldb
  4. #apt-get install python-mysqldb
  5. #python 
  6. Python 2.7.12 (default, Dec  4 2017, 14:50:18)
  7. [GCC 5.4.0 20160609] on linux2
  8. Type "help", "copyright", "credits" or "license" for more information.
  9. >>> import MySQLdb
  10. ...
  11. ImportError: this is MySQLdb version (1, 2, 5, 'final', 1), but _mysql is version (1, 3, 7, 'final', 1) 
  12. #apt-get安装的MySQLdb和mysql版本不一致。
  13. #将python-mysqldb卸载
  14. #apt-get remove --purge python-mysqldb
  15. #用pip重新安装
  16. #pip install mysql-python

手动安装MySQL_python-1.2.5

点击(此处)折叠或打开

  1. #wget https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip
  2. #unzip MySQL-python-1.2.5.zip
  3. #cd MySQL-python-1.2.5
  4. #python setup.py build
  5. #报错如下:
  6. sh: 1: mysql_config: not found
  7. Traceback (most recent call last):
  8.   File "setup.py", line 17, in <module>
  9.     metadata, options = get_config()
  10.   File "/home/ubuntu/MySQL-python-1.2.5/setup_posix.py", line 43, in get_config
  11.     libs = mysql_config("libs_r")
  12.   File "/home/ubuntu/MySQL-python-1.2.5/setup_posix.py", line 25, in mysql_config
  13.     raise EnvironmentError("%s not found" % (mysql_config.path,))
  14. EnvironmentError: mysql_config not found

  15. # apt-get install libmysqlclient-dev
  16. # python setup.py build
  17. running build
  18. running build_py
  19. creating build
  20. creating build/lib.linux-x86_64-2.7
  21. copying _mysql_exceptions.py -> build/lib.linux-x86_64-2.7
  22. creating build/lib.linux-x86_64-2.7/MySQLdb
  23. copying MySQLdb/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb
  24. copying MySQLdb/converters.py -> build/lib.linux-x86_64-2.7/MySQLdb
  25. copying MySQLdb/connections.py -> build/lib.linux-x86_64-2.7/MySQLdb
  26. copying MySQLdb/cursors.py -> build/lib.linux-x86_64-2.7/MySQLdb
  27. copying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdb
  28. copying MySQLdb/times.py -> build/lib.linux-x86_64-2.7/MySQLdb
  29. creating build/lib.linux-x86_64-2.7/MySQLdb/constants
  30. copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
  31. copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
  32. copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
  33. copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
  34. copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
  35. copying MySQLdb/constants/REFRESH.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
  36. copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
  37. running build_ext
  38. building '_mysql' extension
  39. creating build/temp.linux-x86_64-2.7
  40. 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
  41. 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

  42. # python setup.py install
  43. running install
  44. running bdist_egg
  45. running egg_info
  46. writing MySQL_python.egg-info/PKG-INFO
  47. writing top-level names to MySQL_python.egg-info/top_level.txt
  48. writing dependency_links to MySQL_python.egg-info/dependency_links.txt
  49. reading manifest file 'MySQL_python.egg-info/SOURCES.txt'
  50. reading manifest template 'MANIFEST.in'
  51. writing manifest file 'MySQL_python.egg-info/SOURCES.txt'
  52. installing library code to build/bdist.linux-x86_64/egg
  53. running install_lib
  54. running build_py
  55. copying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdb
  56. running build_ext
  57. creating build/bdist.linux-x86_64
  58. creating build/bdist.linux-x86_64/egg
  59. creating build/bdist.linux-x86_64/egg/MySQLdb
  60. copying build/lib.linux-x86_64-2.7/MySQLdb/converters.py -> build/bdist.linux-x86_64/egg/MySQLdb
  61. copying build/lib.linux-x86_64-2.7/MySQLdb/cursors.py -> build/bdist.linux-x86_64/egg/MySQLdb
  62. copying build/lib.linux-x86_64-2.7/MySQLdb/__init__.py -> build/bdist.linux-x86_64/egg/MySQLdb
  63. copying build/lib.linux-x86_64-2.7/MySQLdb/release.py -> build/bdist.linux-x86_64/egg/MySQLdb
  64. copying build/lib.linux-x86_64-2.7/MySQLdb/connections.py -> build/bdist.linux-x86_64/egg/MySQLdb
  65. creating build/bdist.linux-x86_64/egg/MySQLdb/constants
  66. copying build/lib.linux-x86_64-2.7/MySQLdb/constants/FIELD_TYPE.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
  67. copying build/lib.linux-x86_64-2.7/MySQLdb/constants/__init__.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
  68. copying build/lib.linux-x86_64-2.7/MySQLdb/constants/REFRESH.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
  69. copying build/lib.linux-x86_64-2.7/MySQLdb/constants/CR.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
  70. copying build/lib.linux-x86_64-2.7/MySQLdb/constants/CLIENT.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
  71. copying build/lib.linux-x86_64-2.7/MySQLdb/constants/ER.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
  72. copying build/lib.linux-x86_64-2.7/MySQLdb/constants/FLAG.py -> build/bdist.linux-x86_64/egg/MySQLdb/constants
  73. copying build/lib.linux-x86_64-2.7/MySQLdb/times.py -> build/bdist.linux-x86_64/egg/MySQLdb
  74. copying build/lib.linux-x86_64-2.7/_mysql_exceptions.py -> build/bdist.linux-x86_64/egg
  75. copying build/lib.linux-x86_64-2.7/_mysql.so -> build/bdist.linux-x86_64/egg
  76. byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/converters.py to converters.pyc
  77. byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/cursors.py to cursors.pyc
  78. byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/__init__.py to __init__.pyc
  79. byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/release.py to release.pyc
  80. byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/connections.py to connections.pyc
  81. byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/FIELD_TYPE.py to FIELD_TYPE.pyc
  82. byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/__init__.py to __init__.pyc
  83. byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/REFRESH.py to REFRESH.pyc
  84. byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/CR.py to CR.pyc
  85. byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/CLIENT.py to CLIENT.pyc
  86. byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/ER.py to ER.pyc
  87. byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/constants/FLAG.py to FLAG.pyc
  88. byte-compiling build/bdist.linux-x86_64/egg/MySQLdb/times.py to times.pyc
  89. byte-compiling build/bdist.linux-x86_64/egg/_mysql_exceptions.py to _mysql_exceptions.pyc
  90. creating stub loader for _mysql.so
  91. byte-compiling build/bdist.linux-x86_64/egg/_mysql.py to _mysql.pyc
  92. creating build/bdist.linux-x86_64/egg/EGG-INFO
  93. copying MySQL_python.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
  94. copying MySQL_python.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
  95. copying MySQL_python.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
  96. copying MySQL_python.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
  97. writing build/bdist.linux-x86_64/egg/EGG-INFO/native_libs.txt
  98. zip_safe flag not set; analyzing archive contents...
  99. creating dist
  100. creating 'dist/MySQL_python-1.2.5-py2.7-linux-x86_64.egg' and adding 'build/bdist.linux-x86_64/egg' to it
  101. removing 'build/bdist.linux-x86_64/egg' (and everything under it)
  102. Processing MySQL_python-1.2.5-py2.7-linux-x86_64.egg
  103. Copying MySQL_python-1.2.5-py2.7-linux-x86_64.egg to /usr/local/lib/python2.7/dist-packages
  104. Adding MySQL-python 1.2.5 to easy-install.pth file


  105. Installed /usr/local/lib/python2.7/dist-packages/MySQL_python-1.2.5-py2.7-linux-x86_64.egg
  106. Processing dependencies for MySQL-python==1.2.5
  107. Finished processing dependencies for MySQL-python==1.2.5











11-15 10:55