• python3使用Django框架连接mysql(python3+Django+MySQL+pymysql)


    改掉系统默认的sqlite3数据库,

    # Database
    # https://docs.djangoproject.com/en/1.10/ref/settings/#databases

    DATABASES = {
    'default': {
    # 'ENGINE': 'django.db.backends.sqlite3',
    'ENGINE': 'django.db.backends.mysql',
    # 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    'NAME':'djangoDB',
    'USER':'root',
    'PASSWORD':'123456',
    'port':'3306',
    }
    }

    然后启动报错,

    ImportError: No module named 'MySQLdb'

    据说要装MySQL-python

    可是MySQL-python一直无法安装成功。

    又报错ImportError: No module named 'ConfigParser'

    因为python3中叫做configparser,是小写。

    好吧,听说不用MySQL-python可以用pymsql代替,然后就赶紧下载pip install pymysql

    然后再启动,还是不行啊,还是ImportError: No module named 'MySQLdb'

    百度了下,看这篇文章http://www.jianshu.com/p/82781add8449

    加了之后就好了。

    这里说下MySQL-python吧。

    MySQL-python的解释看官方说法

    MySQLdb is an interface to the popular MySQL database server for Python. The design goals are:

    • Compliance with Python database API version 2.0 [PEP-0249]
    • Thread-safety
    • Thread-friendliness (threads will not block each other)

    MySQL-3.23 through 5.5 and Python-2.4 through 2.7 are currently supported. Python-3.0 will be supported in a future release. PyPy is supported.

    说白了就是连接mysql的python接口,有了他就可以用python来操作数据库了。类似java的JDBC那一套东西把。

  • 相关阅读:
    JLOI2012:时间流逝
    bzoj 5217: [Lydsy2017省队十连测]航海舰队
    bzoj 4894: 天赋
    bzoj 4870: [Shoi2017]组合数问题
    bzoj 1558: [JSOI2009]等差数列
    bzoj 4945: [Noi2017]游戏
    bzoj 2142: 礼物
    bzoj 5248: [2018多省省队联测]一双木棋
    51nod2383
    codeforces24D
  • 原文地址:https://www.cnblogs.com/nathanieltian/p/6152940.html
Copyright © 2020-2023  润新知