Bug #41752 Can't connect mysqld which character_set_server=ucs2
Submitted: 26 Dec 2008 6:25 Modified: 2 Aug 2012 21:18
Reporter: Sadao Hiratsuka (Basic Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:5.1.7 OS:Any
Assigned to: Alexander Soklakov CPU Architecture:Any
Tags: encoding, qc

[26 Dec 2008 6:25] Sadao Hiratsuka
Description:
Can't connect mysqld which character_set_server=ucs2

How to repeat:
----- server
[mysqld]
character_set_server = ucs2

----- client
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(
                      "jdbc:mysql://gx240:3306/scott", "scott", "tiger");

----- error message
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '??' at line 1

----- general log
081226 15:04:44    8 Connect    scott@10.133.53.166 on scott
<-- cut -->
                    8 Query     SHOW COLLATION
                    8 Query     xxSET NAMES ucs2 <===== xx are wrong chars

----- workaround
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(
                      "jdbc:mysql://gx240:3306/scott?characterEncoding=UTF-8",
                      "scott", "tiger");

Suggested fix:
Connector/J should set characterEncoding implicitly
when character_set_server = ucs2.
[26 Dec 2008 9:03] Sveta Smirnova
Thank you for the report.

Verified as described.
[6 Jan 2009 18:34] Mark Matthews
The issue is that ucs2 is *not* usable as a client character set. I suppose the driver will have to check if ucs2 is the server character set, and use utf-8 instead, however our utf-8 implementation doesn't cover the full repertoire of ucs-2, so....truncation might occur in some cases.
[2 Aug 2012 21:18] John Russell
Added to changelog for 5.1.22: 

Connecting to a server that used a UCS2 character set would throw an exception:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near '??' at line 1

Now, Connector/J sets characterEncoding implicitly to UTF-8 when the server character set is UCS2. Because the Connector/J UTF-8 implementation does not cover all UCS-2 characters, note that truncation might occur in some cases.