码迷,mamicode.com
首页 > 数据库 > 详细

Ubuntu18.04下mysql无法插入中文的问题

时间:2019-03-20 11:54:34      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:name   输入   数据   原来   nan   var   show   保存   nec   

问题:

   Incorrect string value: ‘\xE6\xB2\x99\xE6\xB2\xB3‘ for column ‘name‘ at row 1

解决:

  在mysql中输入:

    show variables like "char%";

  查看mysql的编码方式:

    +--------------------------+----------------------------+

    | Variable_name | Value |
    +--------------------------+----------------------------+
    | character_set_client | utf8 |
    | character_set_connection | utf8 |
    | character_set_database | latin1 |
    | character_set_filesystem | binary |
    | character_set_results | utf8 |
    | character_set_server | latin1 |
    | character_set_system | utf8 |
    | character_sets_dir | /usr/share/mysql/charsets/ |
    +--------------------------+----------------------------+

  标红的那两行是问题的关键。

  修改配置文件:

    sudo nano /etc/mysql/conf.d/mysql.cnf

    [mysql]

    default-character-set=utf8
    [mysqld]
    character-set-server=utf8

  按Ctrl+o保存,在按ctrl+x退出

  重启mysql服务:

    sudo systemctl restart mysql

  登录mysql查看编码方式:

    show variables like "char%";

    +--------------------------+----------------------------+
    | Variable_name | Value |
    +--------------------------+----------------------------+
    | character_set_client | utf8 |
    | character_set_connection | utf8 |
    | character_set_database | utf8 |
    | character_set_filesystem | binary |
    | character_set_results | utf8 |
    | character_set_server | utf8 |
    | character_set_system | utf8 |
    | character_sets_dir | /usr/share/mysql/charsets/ |
    +--------------------------+----------------------------+

  这样就OK了,但是原来创建的数据库和表还是不支持的,需要重新创建。做好数据的备份。

 

Ubuntu18.04下mysql无法插入中文的问题

标签:name   输入   数据   原来   nan   var   show   保存   nec   

原文地址:https://www.cnblogs.com/mudaol/p/10563924.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!