欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python连接mysql遇到的问题

程序员文章站 2022-05-30 12:29:51
...

由于pthon3.x之后不能用mysql-python了

如果安装mysql-python就会出现错误:

pip install mysql-python
Collecting mysql-python
  Using cached https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/nr/9fz2_qfj6wz4wjnclpr4fdl80000gn/T/pip-install-3gkgsv90/mysql-python/setup.py", line 13, in <module>
        from setup_posix import get_config
      File "/private/var/folders/nr/9fz2_qfj6wz4wjnclpr4fdl80000gn/T/pip-install-3gkgsv90/mysql-python/setup_posix.py", line 2, in <module>
        from ConfigParser import SafeConfigParser
    ImportError: No module named 'ConfigParser'
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/nr/9fz2_qfj6wz4wjnclpr4fdl80000gn/T/pip-install-3gkgsv90/mysql-python/

所有用pip install pymysql

安装好了之后,打开项目的_init_.py,添加代码

import pymysql 

pymysql.install_as_MySQLdb()