Bug #86221 connector/j 5.1.38 cannot connect to MySQL 8.0.1
Submitted: 8 May 2017 16:53 Modified: 16 May 2017 23:42
Reporter: Mark Callaghan Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:5.1.38 OS:Any
Assigned to: Filipe Silva CPU Architecture:Any

[8 May 2017 16:53] Mark Callaghan
Description:
My linkbench client uses connector/j 5.1.38 and this works with MySQL 5.6 and 5.7. It does not work with MySQL 8 as attempts to create a connection get an exception. My client makes a connection here:
https://github.com/mdcallag/linkbench/blob/master/src/main/java/com/facebook/LinkBench/Lin...

Is this expected? 5.1.38 is old, but not that old (2015)
https://mvnrepository.com/artifact/mysql/mysql-connector-java

Connector/J 5.1.42 works for me so maybe this is just a request for a doc update.

How to repeat:
Source code is linkbench and connection is created at https://github.com/mdcallag/linkbench/blob/master/src/main/java/com/facebook/LinkBench/Lin...

Stack trace is:
RROR 2017-05-08 09:41:16,649 [Thread-0]: error connecting to database:
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
        at com.mysql.jdbc.Util.getInstance(Util.java:387)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:917)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:896)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:885)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)
        at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2332)
        at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2085)
        at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:795)
        at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
        at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:400)
        at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:327)
        at java.sql.DriverManager.getConnection(DriverManager.java:664)
        at java.sql.DriverManager.getConnection(DriverManager.java:247)
        at com.facebook.LinkBench.LinkStoreMysql.openConnection(LinkStoreMysql.java:148)
        at com.facebook.LinkBench.LinkStoreMysql.initialize(LinkStoreMysql.java:120)
        at com.facebook.LinkBench.LinkBenchLoad.run(LinkBenchLoad.java:193)
        at com.facebook.LinkBench.LinkBenchDriver$1.run(LinkBenchDriver.java:429)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException

Suggested fix:
Update docs because 5.1.42 works for me
[10 May 2017 11:27] Filipe Silva
Hi Mark,

Thank you for taking the time to report this.

I'm not being able to reproduce this issue, but I'm testing in a standalone application, though. Can you please help me finding what's going on? I have some questions for you, if you don't mind:

- What's the MySQL distribution you're using?
- Does this fail on a standalone application too?
- Can you point out what's the lowest Connector/J version that works?
- What are the OS and Java versions you're using?

Please make your answer private if you prefer.

Thank you,
[10 May 2017 23:52] Mark Callaghan
What is a standalone application? I have a Java application using JDBC that runs against a MySQL database.

For MySQL I am using MySQL 8.0.1, compiled from source.
My host is Ubuntu 16.04

Failure to connect occurs with Connector/J 5.1.38, 5.1.39 and 5.1.40. 
It works with 5.1.41 and 5.1.42

I am able to get connections working for Connector/J 5.1.38, 5.1.39 and 5.1.40 when I add this to my.cnf:
character_set_server=latin1
collation_server=latin1_bin

In the configs that fail for 5.1.38, 5.1.39 and 5.1.40 my.cnf does not set 
character_set_server or collation_server and from SHOW GLOBAL VARIABLES I see that these are the values:
character_set_server    utf8mb4
collation_server        utf8mb4_0900_ai_ci

$ java -version
openjdk version "1.8.0_121"
OpenJDK Runtime Environment (build 1.8.0_121-8u121-b13-0ubuntu1.16.04.2-b13)
OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)
[11 May 2017 11:05] Filipe Silva
Hi Mark,

By a standalone application I meant a simple straightforward code that just connects to the database without going through some application server or other customized class loaders. It's not your case, please ignore.

Thanks for all the information you provided. Actually the next line in the stack trace would have all the information we needed: "at com.mysql.jdbc.ConnectionImpl.getServerCharset(ConnectionImpl.java:3005)". Anyway, your reply helped me getting there as well. :)

The issue you reported is related to the changes introduced in MySQL 8.0.1 wrt the character sets and collations support, with the addition of now being 'utf8mb4' the default char set. Such changes broke the way Connector/J initializes connections.

As you know this was fixed in Connector/J 5.1.41 and I'm sure you already updated your library.

As for the documentation update you suggest, there's nothing we can right now do since MySQL 8.0 is not GA yet. Such failures can happen and are somehow expected in this phase. We highly recommend using the latest connectors with each new MySQL release, especially until it doesn't get GA.

I'm closing this report as "Can't repeat" since latest Connector/J version have this resolved.

Thank you,
[11 May 2017 18:13] Mark Callaghan
why was this closed as can't repeat when you something was done to fix this for 5.1.41?

Is something going to be done to confirm that 5.1.38 can connect to 8.0 when it gets closer to GA?
[11 May 2017 18:37] Mark Callaghan
Why not marked it as fixed or "won't fix"?

I get that 8.0.1 is not GA yet, but marking real problems as "can't repeat" discourages me from filing good bug reports.
[11 May 2017 22:43] Filipe Silva
Hi Mark,

I understand that the status "Can't repeat" may not reflect correctly the current situation, especially from your point-of-view. The bug was actually repeatable, just not in the latest couple versions. Although there will not be any direct reference to this in any release notes, "Closed" should have been the proper status.

When I've set "Can't repeat" I just meant that the bug is not repeatable in latest Connector/J version, which is the one that actually matters, as such there's is nothing left for us to do. If there was an original bug in where this was previously fixed then I would have closed this as "Duplicate" of that other bug, but this wasn't the case because the bad behavior ended up being resolved by internal developments in the driver, in version 5.1.41 as you know, so no bug ended up being associated with this change.

Please accept my apologies for this confusion.

Thank you for your concern,
Filipe
[16 May 2017 13:47] Reggie Burnett
Hi Mark

I've not had the pleasure of meeting you and I look forward to when we can formally be introduced.  I really appreciate you taking the time to file the bug report and using our products.   We truly value our users and the time they give us.

Reggie
[16 May 2017 23:42] Mark Callaghan
Awesome support is the secret to the success of MySQL. Perhaps we will meet at Percona Live, or if they let me attend, Oracle Open World.