ubuntu 下 mysql 插入中文

前端之家收集整理的这篇文章主要介绍了ubuntu 下 mysql 插入中文前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

问题:java.sql.sqlException: Incorrect string value: '\xE5\x85\xAC\xE4\xBC\x91' for column ...

使用Intellij IDEA 编写Spring Boot,集成Hibernate代码时,插入中文数据库中报以上的错,首先检查了URL:

dburl=jdbc:MysqL://localhost:3306/myblog?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=utf-8

OK,没问题,其次查看项目编码:


OK,也没问题,都是UTF8,无奈之下百度之:找到了以下的解决办法:

Ubuntu下设置MysqL字符集为utf8

1.MysqL配置文件地址
/etc/MysqL/my.cnf

2.在[MysqLd]在下方添加以下代码
[MysqLd]
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake

3.重启MysqL服务
sudo service MysqL restart

4.检测字符集是否更新成utf8.
进入MysqLMysqL -u root -p,输入show variables like '%character%' 查看字符集
+--------------------------+----------------------------+
| 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/ |
+--------------------------+----------------------------+

解决办法原文链接 http://www.linuxidc.com/Linux/2016-04/129765.htm

小插曲:我的文件不是/etc/MysqL/my.cnf而是: /etc/MysqL/MysqL.conf.d/MysqLld.cnf

Ubuntu 版本:16.04.2,MysqL版本:Server version: 5.7.18-0ubuntu0.16.04.1 (Ubuntu)

原文链接:https://www.f2er.com/ubuntu/353114.html

猜你在找的Ubuntu相关文章