Re-introduced "Unknown initial character set index" error?

12,367

This talks about the changes that have happened since 8.0 One of the point that has been listed for you to refer is this:

Character Set Support

Important Change: The default character set has changed from latin1 to utf8mb4. These system variables are affected:

The default value of the character_set_server and character_set_database system variables has changed from latin1 to utf8mb4.

The default value of the collation_server and collation_database system variables has changed from latin1_swedish_ci to utf8mb4_0900_ai_ci.

As a result, the default character set and collation for new objects differ from previously unless an explicit character set and collation are specified. This includes databases and objects within them, such as tables, views, and stored programs.


One way to preserve the previous defaults is to start the server with these lines in my.cnf file:

[mysqld]
character_set_server=latin1
collation_server=latin1_swedish_ci

Another option, since you are running docker, is to specify these configuration options as command line arguments to the docker run command. For example:

docker run -d \
--network my-net \
-h mysqldb \
--name mysqldb \
-p 3306:3306 \
-e MYSQL_RANDOM_ROOT_PASSWORD=yes \
-e MYSQL_DATABASE=mydb \
-e MYSQL_USER=admin \
-e "MYSQL_PASSWORD=admin" \
mysql:8 --character-set-server=latin1 --collation-server=latin1_swedish_ci

On the client, if you want to make changes - hopefully these should suffice:

To use 4-byte UTF-8 character sets with Connector/J, configure the MySQL server with character_set_server=utf8mb4, and leave characterEncoding out of the Connector/J connection string.

Connector/J will then auto-detect the UTF-8 setting

Hope this helps!

Share:
12,367
FGreg
Author by

FGreg

Updated on June 07, 2022

Comments

  • FGreg
    FGreg almost 2 years

    I have a Java client application that connects to a mysql server. Both the client and the server are running in docker containers.

    I noticed that the official mysql Docker image recently updated the mysql service to run Version: '8.0.1-dmr'

    Since this change, my Java client application cannot connect to the mysql instance; it fails with the following error:

    Caused by: java.sql.SQLException: Unknown initial character set index '255' received from server. Initial client character set can be forced via the 'characterEncoding' property.
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910) ~[mysql-connector-java-5.0.8-bin.jar:na]
        at com.mysql.jdbc.Connection.configureClientCharacterSet(Connection.java:2412) ~[mysql-connector-java-5.0.8-bin.jar:na]
        at com.mysql.jdbc.Connection.initializePropsFromServer(Connection.java:4139) ~[mysql-connector-java-5.0.8-bin.jar:na]
        at com.mysql.jdbc.Connection.createNewIO(Connection.java:2789) ~[mysql-connector-java-5.0.8-bin.jar:na]
        at com.mysql.jdbc.Connection.<init>(Connection.java:1555) ~[mysql-connector-java-5.0.8-bin.jar:na]
        at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285) ~[mysql-connector-java-5.0.8-bin.jar:na]
        at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:307) ~[tomcat-jdbc-8.0.20.jar:na]
        at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:200) ~[tomcat-jdbc-8.0.20.jar:na]
        at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:699) ~[tomcat-jdbc-8.0.20.jar:na]
        at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:633) ~[tomcat-jdbc-8.0.20.jar:na]
        at org.apache.tomcat.jdbc.pool.ConnectionPool.getConnection(ConnectionPool.java:186) ~[tomcat-jdbc-8.0.20.jar:na]
        at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:126) ~[tomcat-jdbc-8.0.20.jar:na]
    

    I do not own the source code of the Java client application so I cannot easily upgrade the JDBC driver it is using (which is mysql-connector-java-5.0.8-bin.jar).

    This was working with the previous mysqldb:8 docker image which was running mysqld Version: '8.0.0-dmr'

    Is there any workaround to this issue that does not involve updating the JDBC driver? Is this a regression in mysqld?

  • FGreg
    FGreg almost 7 years
    Perfect, that fixed it. I opted for using the command line options --character-set-server=latin1 --collation-server=latin1_swedish_ci instead since I didn't want to create and mount a configuration file to the docker container.
  • N00b Pr0grammer
    N00b Pr0grammer almost 7 years
    Happy to help @FGreg
  • Jonathan Laliberte
    Jonathan Laliberte about 6 years
    editing the my.ini file worked for me, but any ideas why swedish and latin? seems kinda arbitrary
  • N00b Pr0grammer
    N00b Pr0grammer about 6 years
    There have been way too many changes between versions, hence can't point out to a specific reason as of now!