1,在project同名文件夹下的__init__文件中添加如下代码即可 import pymysqlpymysql.install_as_MySQLdb(), 2,修改setting文件 DATABASES = { ‘ default ‘ : { ‘ ENGINE ‘ : ‘ django.db.backends.mysql ‘ , ‘ NAME ‘
1,在project同名文件夹下的__init__文件中添加如下代码即可
import pymysql pymysql.install_as_MySQLdb(),
2,修改setting文件
DATABASES = { ‘default‘: { ‘ENGINE‘: ‘django.db.backends.mysql‘, ‘NAME‘: ‘test2‘, ‘USER‘:‘root‘, ‘PASSWORD‘:‘Gauss_234‘, ‘HOST‘:‘139.155.131.188‘, ‘POST‘:‘3306‘, } }
3,mysql授权
grant all privileges on test2.* to ‘root‘@‘139.155.131.188‘ identified "password" with grant option;
flush privileges;
4,如果这时候启动django会报错
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.
修改\Python35\Lib\site-packages\django\db\backends\mysql\base.py
打开后将如下代码注释:
注释好了之后重新启动django服务器:
会出现以下报错信息、
AttributeError: ‘str‘ object has no attribute ‘decode‘
找到python文件下的django文件>db文件>backends>mysql>operations.py
将decode修改为encode
最后重启服务即可
参考链接:http://www.pianshen.com/article/2285376009/