* 安装pymysql模块

pip install pymysql

* settings.py添加下面设置

## pymysql repalce mysqldb
import pymysql
pymysql.install_as_MySQLdb()

* mysqlclient 版本太低

报错:

raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.

解决:

cd {python_root_dir}/Lib\site-packages\django\db\backends\mysql

base.py

# 找到base.py文件,注释掉 base.py 中如下部分(35/36行)

# if version < (1, 3, 3):
# raise ImproperlyConfigured("mysqlclient 1.3.3 or newer is required; you have %s" % Database.__version__)

* 编码问题

报错:

AttributeError: ‘str’ object has no attribute ‘decode’

解决:

cd {python_root_dir}/Lib\site-packages\django\db\backends\mysql

operations.py

#找到operations.py文件(146行),将decode改为encode
#linux vim 查找快捷键:?decode if query is not None:
query = query.decode(errors='replace')
return query #改为
if query is not None:
query = query.encode(errors='replace')
return query

django 使用PyMySQL连接mysql的更多相关文章

  1. Python3中使用PyMySQL连接Mysql

    Python3中使用PyMySQL连接Mysql 在Python2中连接Mysql数据库用的是MySQLdb,在Python3中连接Mysql数据库用的是PyMySQL,因为MySQLdb不支持Pyt ...

  2. Python 3.2: 使用pymysql连接Mysql

    在python 3.2 中连接MYSQL的方式有很多种,例如使用mysqldb,pymysql.本文主要介绍使用Pymysql连接MYSQL的步骤 1        安装pymysql ·       ...

  3. Python3.x使用PyMysql连接MySQL数据库

    Python3.x使用PyMysql连接MySQL数据库 由于Python3.x不向前兼容,导致Python2.x中的很多库在Python3.x中无法使用,例如Mysqldb,我前几天写了一篇博客Py ...

  4. python基础学习24----使用pymysql连接mysql

    使用pymysql连接mysql 安装pymysql pymysql安装可以通过两种方式 使用pip安装 首先简单说一下pip的使用方法 获取帮助 pip --help 升级 pip pip inst ...

  5. Python3.x:使用PyMysql连接Mysql数据库

    Python3.x:使用PyMysql连接Mysql数据库 Python3.x完全不向前兼容,导致Python2.x中可以正常使用的库,到了Python3就用不了: 比如说mysqldb,目前MySQ ...

  6. 使用PyMySQL连接MySQL错误

    使用PyMySQL连接MySQL错误 之前写了一个小项目,今天突然想起来,准备优化一下,但是原本好好的项目竟然跑不起来了 emmm....我真的啥都没干呀 具体错误是这样的: Traceback (m ...

  7. pycharm pymysql连接mysql 报错 pymysql.err.InterfaceError: (0, '')

    pycharm  pymysql连接mysql  执行MySQL操作遇到以下报错信息: conn.query(q) File "C:\Software\Python37\lib\site-p ...

  8. PyCharm创建Django项目并连接mysql数据库

    0. 安装Django pip install django 1. 新建项目 注:我的Pycharm为社区版,创建项目时,File->New Project- 显示为: ​ 注意勾选内容. 如果 ...

  9. python3.4怎么连接mysql pymysql连接mysql数据库

    本文介绍了python3 4连接mysql数据库的方法,在python3 4中使用原来python2 7的mysqldb已不能连接mysql数据库了,可以使用pymysql.   在python3.4 ...

随机推荐

  1. Union-Find(并查集): Quick union算法

    Quick union算法 Quick union: Java implementation Quick union 性能分析 在最坏的情况下,quick-union的find root操作cost( ...

  2. 十二.Protobuf3编码

    本文档描述了协议缓冲消息的二进制格式.在应用程序中使用Protocol Buffer不需要理解这一点,但是了解不同的Protocol Buffer格式如何影响编码消息的大小会非常有用. 一条简单的信息 ...

  3. git基础问题

    1).git add 与gitstage的区别 git stage只是git add的同义词,所以在使用上没有区别 i)Git仓库的三个组成部分:工作区(Working Directory).暂存区( ...

  4. POJ - 3252 - Round Numbers(数位DP)

    链接: https://vjudge.net/problem/POJ-3252 题意: The cows, as you know, have no fingers or thumbs and thu ...

  5. LeetCode 364. Nested List Weight Sum II

    原题链接在这里:https://leetcode.com/problems/nested-list-weight-sum-ii/description/ 题目: Given a nested list ...

  6. Vector(同步)和Arraylist(异步)的异同

    //  同步  异步  //1  同步  //2  异步  //未响应 = 假死  占用内存过多  内存无法进行处理  //请求方式:同步    异步  //网页的展现过程中:1 css文件的下载  ...

  7. 洛谷 AT2434 JOI 公園 (JOI Park) 题解

    人生第一次AC黑题,我太感动了. 每日一题 day31 打卡 Analysis 先跑遍DJ,求出1到 i的最短路.得到每个点到 1号点的距离后,从小到大排序一遍,这时便可以枚举每个点到 1号点的距离修 ...

  8. C int类型的数组在内存中的地址示例

    #include <stdio.h> int main(void){ int age[5] = {5,6,7,20,99}; return 0; } //转换后 /*(gdb) p &am ...

  9. 洛谷 P2872 [USACO07DEC]道路建设Building Roads 题解

    P2872 [USACO07DEC]道路建设Building Roads 题目描述 Farmer John had just acquired several new farms! He wants ...

  10. Maven 异常 druid jar冲突

    异常: 十二月 25, 2017 11:04:41 下午 org.apache.tomcat.util.digester.SetPropertiesRule begin 警告: [SetPropert ...