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
?
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:
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:Another option, since you are running docker, is to specify these configuration options as command line arguments to the docker run command. For example:
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 leavecharacterEncoding
out of the Connector/J connection string.Connector/J will then auto-detect the
UTF-8
settingHope this helps!