How to configure mysql database in Django1.7 + python 2.78 + pycharm, django1.7pycharm
After virtualenv and virtualenvwrapper are configured, 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:
Copy codeThe 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,
},
}
}