Bug #70949 handshake charset leads error data (Is it a bug in MySQL or in java-connector?)
Submitted: 19 Nov 2013 5:31 Modified: 28 Dec 2013 17:08
Reporter: xiaobin lin (OCA) Email Updates:
Status: No Feedback Impact on me:
None 
Category:MySQL Server: Connection Handling Severity:S3 (Non-critical)
Version:5.1+ OS:Any
Assigned to: CPU Architecture:Any
Tags: charset, handshake, java-connector

[19 Nov 2013 5:31] xiaobin lin
Description:
Description
	In mysql-connector-java-5.1.27, the charset utf8mb4 is supported. But the steps and result bellow looks buggy.
1\	set character_set_server=gbk in my.cnf
2\	start mysql
3\	execute  set global character_set_server=utfmb4;
4\	insert a data with utf8mb4 characters
Result: error data inserted.

Analysis
	Direct reason: Java connector believes that the server use gbk as the default set, so deal the data with the rule of gbk;
	Deeper reason: 
1\ set global character_set_server=utfmb4 just change the global_system_variables, but not the default_charset_info and default_character_set_name. 
2\ when handshake, MySQL server writes server characteristics to client, using default_charset_info->number, 28, which is the CharsetIndex of gbk.

Compare
	As comparison, the steps change to 
1\	set character_set_server= utfmb4 in my.cnf
2\	insert a data with utf8mb4 characters
Result: correct data inserted.
	Because the default charset is utfmb4 now, the connector treats dada correctly.

How to repeat:
As above

Suggested fix:
There are two ways to resolve this problem.
	1\ MySQL sends the current character info number in global_system_variables when handshake
	2\ Java connector get the correct character to use by “select @@character_set_server;”

So , is it a bug for MySQL or java-connector?
[19 Nov 2013 19:53] Sveta Smirnova
Thank you for the report.

I assume you insert data using Connector/J? If so, did you reconnect after issues SET GLOBAL character_set_server?
[20 Nov 2013 1:04] xiaobin lin
hi, Sveta, yes, Connector/J is used.
The client starts after  SET GLOBAL character_set_server. Before it starts, I had checked there was only one connection (self) by "show processlist"
[22 Nov 2013 18:41] Sveta Smirnova
Thank you for the feedback.

I can not repeat described behavior with small test. Which version of MySQL server do you use?
[27 Nov 2013 21:19] xiaobin lin
both 5.5 or 5.6 can repeat.
And from the source code, we can see that
1\ the "set global ..." can not change the default_ configuration.
2\ When handshare, MySQL send the default charset number
[28 Nov 2013 17:08] Sveta Smirnova
Thank you for the feedback.

In this case, please, provide Java test case, demonstrating the issue: looks like I am trying in wrong way.
[29 Dec 2013 1:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".