Home > Article > Backend Development > Django1.7+python 2.78+pycharm configure mysql database
After configuring virtualenv and virtualenvwrapper, use pycharm to create a new project. The problem to be faced later comes. I have been using SQLite as the development database for learning. 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 it and use it more likely. Develop on the mysql database deployed in the production environment.
I thought it was something that should be easy, but unexpectedly I ran into some trouble
According to Baidu, the solutions found are probably:
MySQLdb
The connector that comes with mysql installation
pymysql
MySQLdb is the first database link library officially recommended by Django, and it was naturally the first one I tried. However, during the installation, I couldn't find the installation file suitable for 64-bit, python2.78! After introducing modifications in an article, I reluctantly installed a version that supports 2.7. As a result, unicode errors were always reported when using it, and the mysql database also followed the tutorial. The setting was changed to utf8 encoding, so I had to give it up
2, built-in connector
Another version that looks very official, but according to the official installation method, it always prompts that the mysql.connector.django module is not available. . . . Don't understand why. After searching carefully, I found that the students who had successfully installed it encountered Chinese unicode errors. . . . . Sorry
3,pymysql
This is the solution on the blog about trying out django-mysql with python3. It was not used at first because it was unofficial, but it was unexpectedly easy and successful. . .
Add in project’s inti.py:
import pymysql pymysql.install_as_MySQLdb() settings: DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', #数据库引擎 'NAME': 'django', #数据库名 'USER': 'user', #用户名 'PASSWORD': 'password!', #密码 'HOST': 'localhost', #数据库主机,默认为localhost 'PORT': '3306', #数据库端口,MySQL默认为3306 'OPTIONS': { 'autocommit': True, }, } }