Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.sql.SQLException: Unknown initial character set index '255' received from server for connector 8.0.11

Tags:

java

mysql

jdbc

While establishing the connection to a MySQL database, I'm getting the following error

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

Upon googling, I got to know that we need to modify 2 params in my.ini or my.cnf.

I am using MySQL version 8.0.11 and it does not have this file.

Hence I modified these parameters using the SQL commands:
Please note name and duration are column name in the table.

ALTER TABLE courses MODIFY name VARCHAR(50) COLLATE utf8_unicode_ci;    
ALTER TABLE courses MODIFY duration VARCHAR(50) COLLATE utf8_unicode_ci;

ALTER TABLE courses MODIFY name VARCHAR(50) CHARACTER SET utf8;
ALTER TABLE courses MODIFY duration VARCHAR(50) CHARACTER SET utf8;

Hence my table looks like this

Table

After this, I restarted MySQL server, but I'm still getting the above error.

Please note I'm deploying my application in tomcat and running rest API call which will connect to the database. While connecting to the database, I'm getting the above error.

like image 231
sachin sarangamath Avatar asked May 22 '18 18:05

sachin sarangamath


2 Answers

You can add ?characterEncoding=latin1" after your url String like this for e.g.:

"jdbc:mysql://localhost/yourDB?characterEncoding=latin1";

It might work.

like image 197
Manish Patel Avatar answered Oct 02 '22 22:10

Manish Patel


Using MySQLWorkbench interface:

First click in your connection ->

enter image description here

After click in Options File

enter image description here

And change character-set-server and collation-server values to the values below:

enter image description here

Make sure to restart mysql server by opening services and restarting mysql server.

like image 24
Knautiluz Avatar answered Oct 03 '22 00:10

Knautiluz