zoukankan      html  css  js  c++  java
  • Mysql写入记录出现 Incorrect string value: 'xB4xE7xB1xCAxBCxC7‘错误?(写入中文)

    Mysql写入记录出现 Incorrect string value: 'xB4xE7xB1xCAxBCxC7‘错误?

    解决方法一:

    在创建数据表时就需要注意将中文字段属性设置为utf8编码形式

    CREATE TABLE tdb_goods_types(
    type_id SMALLINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
    type_name VARCHAR(20) character set utf8 collate utf8_unicode_ci not null,
    parent_id SMALLINT UNSIGNED NOT NULL DEFAULT 0
    );

    解决方法二:

    创建时不需要指定,之后进行修改

    第一步:修改MySQL该字段的字符集与整理规则即可。假设数据表为phplamp, SQL语句的字符集为utf8,出错的字段为address:  

    MySQL 1366 错误解决办法  

       1. #检查数据表所有字段的状态  

       2. ->show full columns from phplamp;  

       3. #发现address字段的Collation项非utf8,修改它!  

       4. ->alter table phplamp change address address varchar(100) character set utf8 collate utf8_unicode_ci not null;  

    修改完字段的字符集后可以再使用show full columns from table_name命令检查一下,以确保万无一失。假如您的SQL字符集为GBK或是GB2312或是其它的话,只需要将数据表字段的字符集更改为其相应的编码即可。

    第二步:将客户端设为以GBK编码来显示数据,

    SET NAMES GBK;

    这只是但不影响数据存储,数据库还是原来的UTF8编码。

  • 相关阅读:
    [译]K-D-B-tree(草稿,第一次翻译)
    [LeetCode]Letter Combinations of a Phone Number
    [LeetCode]Multiply Strings
    [LeetCode]Populating Next Right Pointers in Each Node
    [LeetCode]Sum Root to Leaf Numbers
    [LeetCode]String to Integer (atoi)
    [LeetCode]Path Sum II
    [LeetCode]Minimum Depth of Binary Tree
    线上死锁问题排查
    Redis(四):独立功能的实现
  • 原文地址:https://www.cnblogs.com/Yanjy-OnlyOne/p/12618140.html
Copyright © 2011-2022 走看看