Have python 3 support mysqldb's solution
- 2020-05-26 09:28:41
- OfStack
preface
In the New Year I wish you all ES6, php PHP7, Java JAVA9, python python 3. Okay, so let's get to the main point of this article. You might be used to mysqldb in python2.x, but that component is no longer supported in python3.x. What if you also want python 3 to support mysqldb? Let's take a look.
why
MySQLdb is only suitable for python2.x. It is found that pip cannot be installed. Its replacement in py3 is:
import pymysql
pip install pymysql
django+mysql
By default, Django still USES MySQLdb: to execute the bulletin:
ImportError: No module named 'MySQLdb'
Solution:
In the site
__init__.py
Add to file
import pymysql
pymysql.install_as_MySQLdb()
conclusion