Bug #113637 wrong result after execute "set global character_set_client"
Submitted: 14 Jan 2024 13:52 Modified: 15 Jan 2024 10:53
Reporter: Wenliang Xu Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:MySQL8.2.0 OS:Linux
Assigned to: CPU Architecture:Any

[14 Jan 2024 13:52] Wenliang Xu
Description:
Description:
  When you log in to the MySQL client and execute the command "set global character_set_client=xxx", and then exit the current session and log in again, you will see that the variable values at the session level and the global level are different.

How to repeat:
1. Create a MySQL instance with version 8.2.0
2. log in MySQL client, view the value of the "character_set_client" 
mysql> show variables like "%char%";
+--------------------------+---------------------------------------+
| Variable_name            | Value                                 |
+--------------------------+---------------------------------------+
| character_set_client     | utf8mb4                               |
| character_set_connection | utf8mb4                               |
| character_set_database   | utf8mb4                               |
| character_set_filesystem | binary                                |
| character_set_results    | utf8mb4                               |
| character_set_server     | utf8mb4                               |
| character_set_system     | utf8mb3                               |
| character_sets_dir       | /opt/mysql/base/8.2.0/share/charsets/ |
+--------------------------+---------------------------------------+
8 rows in set (0.01 sec)

mysql> show  global variables like "%char%";
+--------------------------+---------------------------------------+
| Variable_name            | Value                                 |
+--------------------------+---------------------------------------+
| character_set_client     | utf8mb4                               |
| character_set_connection | utf8mb4                               |
| character_set_database   | utf8mb4                               |
| character_set_filesystem | binary                                |
| character_set_results    | utf8mb4                               |
| character_set_server     | utf8mb4                               |
| character_set_system     | utf8mb3                               |
| character_sets_dir       | /opt/mysql/base/8.2.0/share/charsets/ |
+--------------------------+---------------------------------------+

3.Execute setting global character_set_client=utf8mb3,then exit the current session 
mysql> set global character_set_client=utf8mb3;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> quit

5.Log in again,view the value of the "character_set_client"  
mysql> show variables like "%char%";
+--------------------------+---------------------------------------+
| Variable_name            | Value                                 |
+--------------------------+---------------------------------------+
| character_set_client     | utf8mb4                               |
| character_set_connection | utf8mb4                               |
| character_set_database   | utf8mb4                               |
| character_set_filesystem | binary                                |
| character_set_results    | utf8mb4                               |
| character_set_server     | utf8mb4                               |
| character_set_system     | utf8mb3                               |
| character_sets_dir       | /opt/mysql/base/8.2.0/share/charsets/ |
+--------------------------+---------------------------------------+
8 rows in set (0.01 sec)

mysql> show  global variables like "%char%";
+--------------------------+---------------------------------------+
| Variable_name            | Value                                 |
+--------------------------+---------------------------------------+
| character_set_client     | utf8mb3                               |
| character_set_connection | utf8mb4                               |
| character_set_database   | utf8mb4                               |
| character_set_filesystem | binary                                |
| character_set_results    | utf8mb4                               |
| character_set_server     | utf8mb4                               |
| character_set_system     | utf8mb3                               |
| character_sets_dir       | /opt/mysql/base/8.2.0/share/charsets/ |
+--------------------------+---------------------------------------+

more ,I also  make a test for "set global character_set_connection=utfmb3" and "set global character_set_results=utfmb3",find the same problem.
[15 Jan 2024 10:53] MySQL Verification Team
Hi Mr. Xu,

Thank you for your bug report.

However, this is not a bug.

Our Reference Manual clearly points out that it is not possible to set a client character set in the way that you describe. You simply have to set default-character-set to the one you desired, in your program. Some of MySQL utilities , like MySQL CLI, allow this to be specified in the arguments. 

When you start your MySQL client, then you get, for example with --default-character-set=binary:

+--------------------------+----------------------------------------------------------------------+
| Variable_name            | Value                                                                |
+--------------------------+----------------------------------------------------------------------+
| character_set_client     | binary                                                               |
| character_set_connection | utf8mb4                                                              |
| character_set_database   | utf8mb4                                                              |
| character_set_filesystem | binary                                                               |
| character_set_results    | utf8mb4                                                              |
| character_set_server     | utf8mb4                                                              |
| character_set_system     | utf8mb3                                                              |
| character_sets_dir       |  ........................................
+--------------------------+----------------------------------------------------------------------+

Not a bug.