[MySQL]--MySQL表中某个列插入数据总被截断,报编码方式的语法错误,实际是column的not null属性和更改编码语法导致的冲突。

  MySQL的编码方式中,常用的有gb2312<gbk<utf8。

  MySQL的编码方式的查看,常用三个参数:character_set_client, character_set_connection ,character_set_result.

         

  

  查询goods表的列的编码情况: show full columns from goods;

  

 

 

 

  在三个参数一样的情况下,发现goods表中的goods_name的值被截断了,单独插入一行数据的时候,报字符编码错误。

      

 

 

   

  用alter table change语法来修改列的默认字符集,结果报错ERROR 1064. 自己没发现语法错在什么地方。

    mysql> alter table goods change goods_name goods_name varchar(120) not null character set utf8 ;
    ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'character set utf8' at line 1
    mysql>

  

  后来去掉了not null之后,发现更新字符集语句可以正常更新了

  mysql> alter table goods change goods_name goods_name varchar(120) not null character set utf8 ;
  ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'character set utf8' at line 1
  mysql>
  mysql>
  mysql>
  mysql> alter table goods change goods_name goods_name varchar(120) character set utf8 ;
  Query OK, 0 rows affected (0.08 sec)
  Records: 0 Duplicates: 0 Warnings: 0

  

  

  

 

posted on 2020-03-02 21:44  gaomatlab  阅读(458)  评论(0编辑  收藏  举报

导航