问题:

插入数据时,报了这样一个错误:“_mysql_exceptions.Warning: Incorrect string value: ‘\xE6\xB5\x81\xE8\xA1\x8C…’ for column ‘name’ at row 1”。

我使用了中文的数据,看起来就是一个字符集不兼容的错误;Django默认使用UTF-8,而mysqld那边配置是默认使用了latin1 – default collation 。

解决办法如下:

(1)设置my.cnf

vim /etc/mysql/my.cnf

[mysqld]

character_set_server=utf8

service mysql restart

(2)创建数据库指定编码

CREATE DATABASE football DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

(3)shell文件方式

mysql -uroot -p123456 <<EOF
drop database football;
CREATE DATABASE football DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
EOF

mysql character set exception的更多相关文章

  1. mysql: Character set 'utf8mb4' is not a compiled character set and is not specified in the '/usr/share/mysql/charsets/Index.xml' file

    mysql: Character set 'utf8mb4' is not a compiled character set and is not specified in the '/usr/sha ...

  2. mysql死锁com.mysql.cj.jdbc.exception.MYSQLTransactionRollbackException Deadlock found when trying to get lock;try restarting transaction

    1.生产环境出现以下报错 该错误发生在update操作中,该表并未建立索引,也就是只有InnoDB默认的主键索引,发生错误的程序是for循环中update. 什么情况下会出现Deadlock foun ...

  3. MySQL报错: Character set ‘utf8mb4‘ is not a compiled character set and is not specified in the ‘/usr/share/mysql/charsets/Index.xml‘ file

    由于日常程序使用了字符集utf8mb4,为了避免每次更新时,set names utf8mb4,就把配置文件改了,如下: [root@~]# vim /etc/my.cnf #my.cnf [clie ...

  4. MySQL基础知识:Character Set和Collation

    A character set is a set of symbols and encodings. A collation is a set of rules for comparing chara ...

  5. mysql python image

    连接mysql数据库: cnx = mysql.connector.connect(user='joe', database='test') Connector/Python参数列表 Argument ...

  6. java 实现mysql数据库导出

    package com.zbb.util; import java.io.BufferedReader;import java.io.File;import java.io.FileInputStre ...

  7. python---连接MySQL第五页

    Connector/Python Connection Arguments A connection with the MySQL server can be established using ei ...

  8. (转) Eclipse连接MySQL数据库(傻瓜篇)

    Eclipse连接MySQL数据库(傻瓜篇) 原帖地址: http://www.cnblogs.com/fnng/archive/2011/07/18/2110023.html Posted on 2 ...

  9. Navicat for mysql 显示中文乱码问题

    使用navicat for mysql 打开数据库时,使用Console插入和查询数据显示乱码 处理过程 1.查看数据库编码为" utf8 -- UTF-8 Unicode",也就 ...

随机推荐

  1. 修改 jquery.validate.js 支持非form标签

    尝试使用markdown来写一篇blog,啦啦啦 源代码传送门:github 在特殊情况下我们使用jquery.validate.js对用户输入的内容做验证的时候,表单并不是一定包含在form之中,有 ...

  2. canvas

    1. 画布可以通过两只手指上下移动,画布大小默认为屏幕大小的2倍,通过自定义View,嵌套scollview实现. Y 2. 通过处理手指触摸事件,一根手指时,使用Canvas绘制移动路径,产生直线: ...

  3. List [][]

    # -*- coding:utf-8 -*-   L = [     ['Apple', 'Google', 'Microsoft'],     ['Java', 'Python', 'Ruby', ...

  4. 用css3做一个正方体

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  5. Python安装pywinauto时遇到error: The read operation timed out解决方法

    Python结合Pywinauto 进行 Windows UI 自动化,安装pywinauto时遇到的一些问题: 解决方法:很明显是链接超时国外网站你懂的V_P_N吧,直接通过报错信息的链接复制到浏览 ...

  6. RocketMQ原理解析-Consumer

    consumer 1.启动 有别于其他消息中间件由broker做负载均衡并主动向consumer投递消息,RocketMq是基于拉模式拉取消息,consumer做负载均衡并通过长轮询向broker拉消 ...

  7. 定位框一闪而过 iOS Swift

    需求:获取经纬度. 方案:我自定义了一个类模块CLLocationModule.swift 备注以下代码里 let IS_IOS8 = (UIDevice.currentDevice().system ...

  8. 各个浏览器显示版本(IE,火狐)

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. IScroll5兼容IE修改

    水平不到家,无法像js大神那样讲得头头是道.仅做记录,以备后查. iScroll5是不兼容IE低版本的.为兼容IE低版本(以IE8为例),需做以下工作: 1.事件绑定方式兼容 众所周知,独特的IE有它 ...

  10. 用Canvas实现动画效果

    1.清除Canvas的内容 clearRect(x,y,width,height)函数用于清除图像中指定矩形区域的内容 <!doctype html> <html> <h ...