Originally, it was easy to configure the mysql database in the Django1.7 + python2.78 + pycharm environment. as a result, I found that there were many problems, record the final configuration result here. For more information about how to configure virtualenv and virtualenvwrapper, use pycharm to create a new project. The problems that we will face later come. we have been learning sqlite as a development Database. according to the principles of the previous tutorials, it seems that the development environment should be as consistent as possible with the production environment, so now I want to try to use a mysql database that is more likely to be deployed in the production environment for development.
I thought it was a very easy task, but I didn't expect any trouble.
According to a channel called Baidu, the following solutions are available:
MySQLdb
Mysql connector
Pymysql
MySQLdb
This is the first database link Library officially recommended by django. it is naturally my first attempt. However, no installation file suitable for 64-bit python2.78 was found during installation! After an article about the modification, we barely installed a version that supports version 2.7. unicode errors are always reported when the result is used, and mysql databases are set to utf8 encoding according to the tutorial.
2. built-in ctor
It is also a very official version, but according to the official installation method, it is always prompted that there is no mysql. connector. django module .... I don't understand why. After finding out that the installation was successful, I encountered a Chinese unicode error ..... Concept
3. pymysql
This is the solution for using django-mysql in python3 on the blog. At first, it was an unexpected success because it was not officially used...
Add:
The code is as follows:
Import pymysql
Pymysql. install_as_MySQLdb ()
Settings:
DATABASES = {
'Default ':{
'Engine ': 'Django. db. backends. mysql', # Database ENGINE
'Name': 'Django ', # Database NAME
'User': 'user', # USER name
'Password': 'Password! ', # Password
'Host': 'localhost', # Database HOST. the default value is localhost.
'Port': '123', # Database PORT. MySQL is 3306 by default.
'Options ':{
'Autocommit ': True,
},
}
}