python3+pymysql

来源:互联网 发布:网络用语鲤鱼什么意思 编辑:程序博客网 时间:2024/05/16 07:04

python3已不支持mysqldb,今天在连接数据库的时候遇到很多问题,记之。

pymysql 安装

  1. pip安装
$ pip install PyMySQL

由于我的Python3 不在c盘,所以

$ python -m pip install PyMySQL
  1. git安装
$ git clone https://github.com/PyMySQL/PyMySQL$ cd PyMySQL/$ python3 setup.py install

使用

在项目的(不是app)的init.py文件里

import pymysqlpymysql.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

0 0
原创粉丝点击