关于生成数据库字段时 mysql编码报错

来源:3-8 .管理员-登录日志-操作日志数据模型设计

hars

2017-07-29

在执行model.py时候,数据可以正常生成,但是程序会报警告

C:\Python36\lib\site-packages\pymysql\cursors.py:166: Warning: (1366, 
"Incorrect string value: '\\xD6\\xD0\\xB9\\xFA\\xB1\\xEA...' for column 'VARIABLE_VALUE' at row 480")
  result = self._query(query)

这时候搜索问题,都表示是数据库编码问题,普遍解决方法是,修改my.ini文件,重启数据库

[client]
default-character-set=utf8

[mysql]
default-character-set=utf8

[mysqld]
collation-server = utf8_unicode_ci
init-connect=’SET NAMES utf8′
character-set-server=utf8

此时新建movie数据库后,编码改变成功

mysql> status;                                                                                                                 
--------------                                                                                                                 
mysql  Ver 14.14 Distrib 5.7.17, for Win64 (x86_64)                                                                            
                                                                                                                               
Connection id:          15                                                                                                     
Current database:       movie                                                                                                  
Current user:           root@localhost                                                                                         
SSL:                    Not in use                                                                                             
Using delimiter:        ;                                                                                                      
Server version:         5.7.17-log MySQL Community Server (GPL)                                                                
Protocol version:       10                                                                                                     
Connection:             localhost via TCP/IP                                                                                   
Server characterset:    utf8                                                                                                   
Db     characterset:    utf8                                                                                                   
Client characterset:    utf8                                                                                                   
Conn.  characterset:    utf8                                                                                                   
TCP port:               3306                                                                                                   
Uptime:                 29 min 24 sec                                                                                          
                                                                                                                               
Threads: 1  Questions: 297  Slow queries: 0  Opens: 697  Flush tables: 1  Open tables: 519 
 Queries per second avg: 0.168      
--------------

但是生成数据字段,虽然仍然能成功,但是报错仍然存在,不知道老师有好的解决方法没有?

写回答

4回答

小蜗牛不回头

2017-07-30

你的 collation-server 跟我不一样。

//szimg.mukewang.com/597daf100001d4fa10620648.jpg

1
2
hars
折腾好长时间了,零零碎碎的先不管了,能正常插入数据,先正常向下走。
2017-07-30
共2条回复

rustgopy

2017-07-29

添加遇到中文的时候,在python中处理一下,转化为unicode,使用u"中文"转化,有问题及时与老师反馈!

1
1
hars
好的,老师。
2017-07-30
共1条回复

rustgopy

2017-07-29

亲,你好,数据库编码的问题,你执行如下语句:

1.查看movie数据库

show create database movie\G

2.查看数据表

use movie;
show create table user\G

然后把截图给老师看看!

1
1
hars
不好意思老师,系统崩了,安装环境到现在,耽误时间了。我把图贴上来,您帮我看看。
2017-07-30
共1条回复

hars

提问者

2017-07-30

老师早点休息,白天再帮我看就好了。movie数据库和user表的状态是这样的

//szimg.mukewang.com/597cd8b70001987812651040.jpg

0
2
我屋园园
Warning: (1366, "Incorrect string value: '\\xD6\\xD0\\xB9\\xFA\\xB1\\xEA...' for column 'VARIABLE_VALUE' at row 478") result = self._query(query) 我还是会出现
2017-09-27
共2条回复

Python Flask 构建微电影视频网站

Python 最好用轻量级框架,让你轻松胜任 Python Web 工程师

683 学习 · 663 问题

查看课程