python3已不支持mysqldb,今天在连接数据库的时候遇到很多问题,记之。
pymysql 安装
- pip安装
$ pip install PyMySQL
由于我的Python3 不在c盘,所以
$ python -m pip install PyMySQL
- git安装
$ git clone https://github.com/PyMySQL/PyMySQL
$ cd PyMySQL/
$ python3 setup.py install
使用
在项目的(不是app)的init.py文件里
import pymysql
pymysql.install_as_MySQLdb()
bug-1045
在makemigrations时出现了—1045, “Access denied for user ‘someuser’@’localhost’ (using password: YES)”
找了好久才解决
In my case the settings.py has the following:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'TRYDJANGO',
'USERNAME':'user_trydjango',
'PASSWORD':'passtry',
'PORT':'3306',
'HOST': 'localhost',
}
}
And it works if I change the ‘USERNAME’ to ‘USER’:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'TRYDJANGO',
'USER':'user_trydjango',
'PASSWORD':'passtry',
'PORT':'3306',
'HOST': 'localhost',
}
}
Django : mysql : 1045, “Access denied for user—stackoverflow