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
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.
解决方案
Using MySQLWorkbench interface:
First click in your connection ->
After click in Options File
And change character-set-server and collation-server values to the values below:
Make sure to restart mysql server by opening services and restarting mysql server.