修改mysql数据的字符集

今天遇到了一个异常,在插入数据库的时候报错,报错内容如下:

### Error updating database.  Cause: java.sql.SQLException: Incorrect string value: '\xE5\x8F\xA3\xE7\x81\xAB...' for column 'name' at row 1
### The error may exist in com/cashway/record/mapper/BusinessMapper.java (best guess)
### The error may involve com.cashway.record.mapper.BusinessMapper.insert-Inline
### The error occurred while setting parameters
### SQL: INSERT INTO tb_business  ( id, pid, name,  created_by, created_time, updated_by, updated_time )  VALUES  ( ?, ?, ?,  ?, ?, ?, ? )
### Cause: java.sql.SQLException: Incorrect string value: '\xE5\x8F\xA3\xE7\x81\xAB...' for column 'name' at row 1
; uncategorized SQLException; SQL state [HY000]; error code [1366]; Incorrect string value: '\xE5\x8F\xA3\xE7\x81\xAB...' for column 'name' at row 1; nested exception is java.sql.SQLException: Incorrect string value: '\xE5\x8F\xA3\xE7\x81\xAB...' for column 'name' at row 1
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:89) ~[spring-jdbc-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) ~[spring-jdbc-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) ~[spring-jdbc-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:91) ~[mybatis-spring-2.0.6.jar:2.0.6]

查了一波是说数据库字符集有问题,所以在保存中文内容的时候会报错,需要改数据库的字符集,于是便有了下面这句,修改数据库的字符集。

alter database 数据库名 character set utf8;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值