Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@@global.character_set_connection seems take no effect for new connections #53167

Open
lcwangchao opened this issue May 10, 2024 · 1 comment
Labels
severity/moderate sig/sql-infra SIG: SQL Infra type/bug This issue is a bug.

Comments

@lcwangchao
Copy link
Collaborator

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

mysql> set @@global.character_set_connection="latin1";

Then schedule a new connection using MySQL client:

$ mysql --comments --host 127.0.0.1 -uroot -P4000
mysql> select @@global.character_set_connection, @@character_set_connection;

2. What did you expect to see? (Required)

I use a mysql client with version 8.0.33 to do this test

$ mysql --version
mysql  Ver 8.0.33 for macos13.3 on arm64 (Homebrew)

In mysql 8.0.33, the new connection has the same @@character_set_connection with global settings:

$ mysql --comments --host 127.0.0.1 -uroot -P3306
mysql> select @@global.character_set_connection, @@character_set_connection;
+-----------------------------------+----------------------------+
| @@global.character_set_connection | @@character_set_connection |
+-----------------------------------+----------------------------+
| latin1                            | latin1                     |
+-----------------------------------+----------------------------+
1 row in set (0.00 sec)

mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.33    |
+-----------+
1 row in set (0.01 sec)

3. What did you see instead (Required)

But for TiDB, @@global.character_set_connection does not take effect:

> mysql --comments --host 127.0.0.1 -uroot -P4001
mysql> select @@global.character_set_connection, @@character_set_connection;
+-----------------------------------+----------------------------+
| @@global.character_set_connection | @@character_set_connection |
+-----------------------------------+----------------------------+
| latin1                            | utf8mb4                    |
+-----------------------------------+----------------------------+
1 row in set (0.00 sec)

4. What is your TiDB version? (Required)

master

@lcwangchao lcwangchao added type/bug This issue is a bug. sig/sql-infra SIG: SQL Infra severity/moderate labels May 10, 2024
@lcwangchao
Copy link
Collaborator Author

There are 3 places where the charset can be set:

When ExecuteStmt is called, it will call loadCommonGlobalVariablesIfNeeded to load the global variable to the current session. However, for character_set_connection, the skipInit is set as true which means this step will be skipped:

{Scope: ScopeGlobal | ScopeSession, Name: CollationConnection, Value: mysql.DefaultCollationName, skipInit: true, Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) {

That's why the global settings of character_set_connection does not take effect.

  • Some clients will also run an extra statement SET NAMES ... after the handshake. Then the charset/collation in the current session will be reset too. That depends on the client and its configurations. For MySQL client with version 8.0.3, it does not do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity/moderate sig/sql-infra SIG: SQL Infra type/bug This issue is a bug.
Projects
None yet
Development

No branches or pull requests

1 participant