What is PyMySQL and how does it differ from MySQLdb? Can it affect Django deployment?

后端 未结 5 858
情歌与酒
情歌与酒 2020-12-01 01:18

I just solved some problems in my Django 1.3 app by using PyMySQL instead of MySQLdb. I followed this tutorial on how to make the switch: http://web-eng-help.blogspot.com/20

5条回答
  •  眼角桃花
    2020-12-01 01:44

    PyMySQL and MySQLdb provide the same functionality - they are both database connectors. The difference is in the implementation where MySQLdb is a C extension and PyMySQL is pure Python.

    There are a few reasons to try PyMySQL:

    • it might be easier to get running on some systems
    • it works with PyPy
    • it can be "greened" and works with gevent

    The proper way to use it with Django is to import it and tell it to impersonate MySQLdb in your top-level file, usually manage.py. Put the following code at the very top of your manage.py (or whatever file you call when starting your server):

    try:
        import pymysql
        pymysql.install_as_MySQLdb()
    except ImportError:
        pass
    

提交回复
热议问题