While establishing the connection to a MySQL database, I\'m getting the following error
java.sql.SQLException: Unknown initial character set index \'255\' receiv
Setting the CharacterEnconding, useUnicode options will work
jdbc:mysql://localhost:3306/dbname?characterEncoding=utf8&useSSL=false&useUnicode=true"
Use the same version of MySQL as well as mysql-connector. If you are using tomcat then keep the connector in the lib folder of tomcat.
Add connector dependency jar file in the POM file after a cross-check with your MySql server version 8.0.x add this dependency it was working for me mysqlmysql-connector-java 8.0.11
I am using springboot
,liquibase
, mysql
I got solution:
This error occur just because of mysql connector in dependency and mysql server you install not match(in my case i am using lower version mysql connector and latest mysql server). So just change scope of mysql connector to runtime
:
maven
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
gradle
dependencies {
//... other dependencies
runtimeOnly group:'mysql', name:'mysql-connector-java'
}
Or if problem yet not solve then use same version or nearby version for both mysql server and mysql connector.
With version 8 the default characterset changed. When you add your character set to the connection URL like ?characterEncoding=latin1 it might work.
it is because of mysql-connector version , i,e. My-sql install version and dependency version did not match.
use same version for myS