Unknown initial character set index '255' received from server. Initial client character set can be forced via the 'characterEncoding' property.

问题描述

在执行Sql时遇到了如下错误

1
Unknown initial character set index '255' received from server. Initial client character set can be forced via the 'characterEncoding' property.

image-20240906160028483

解决方案

1、在连接数据库时指定字符集

1
jdbc.url=jdbc:mysql://localhost:3306/mybatis?useUnicode=true&characterEncoding=utf8

在主配置文件填写url应该选用&,如果是在java中需要用 &

2、检查Mysql驱动配置是否正确

因为我本地使用的Mysql的版本是8,而导入依赖的版本是5,修改后重新加载依赖就正常了

1
2
3
4
5
6
7
<!-- MySQL驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<!-- <version>5.1.3</version>-->
<version>8.0.33</version>
</dependency>

需要注意的是,不同版本的Mysql驱动地址有所区别

1
2
3
4
5
# Mysql 5
jdbc.driver=com.mysql.jdbc.Driver

# Mysql 8+
jdbc.driver=com.mysql.cj.jdbc.Driver

参考

【mybatis】遇到的问题(Unknown initial character set index ‘255‘ received from server)

Unknown initial character set index ‘255’ received from server. 解决方法