zoukankan      html  css  js  c++  java
  • [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

      

      

      

  • 相关阅读:
    [网络流24题]飞行员配对方案问题
    学习笔记——线性基
    HDU 4507 吉哥系列故事——恨7不成妻(数位DP求平方和)
    bzoj1415&洛谷P4206 [NOI2005]聪聪与可可
    后缀自动机(模板+例题)
    最小表示法(模板)poj1059
    求次小生成树(洛谷P4180&bzoj1977)
    KMP poj3942
    最小表示法(模板) CH1807
    数位dp 求山峰数(hill)
  • 原文地址:https://www.cnblogs.com/gaochsh/p/12398243.html
Copyright © 2011-2022 走看看