Bug #59791 GRANT SUPER changes character_set_client value
Submitted: 28 Jan 2011 9:54 Modified: 28 Jan 2011 13:57
Reporter: Artur Wosinski Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Charsets Severity:S3 (Non-critical)
Version:5.1.52 OS:Linux
Assigned to: CPU Architecture:Any

[28 Jan 2011 9:54] Artur Wosinski
Description:
When I grant "super" privilege to user, charset settings are changing:
before grant:

 mysql -u uswer -p --host 10.24.20.100 -e "show variables like '%char%';"
Enter password: 
+--------------------------+----------------------------------------+
| Variable_name            | Value                                  |
+--------------------------+----------------------------------------+
| character_set_client     | utf8                                   |
| character_set_connection | utf8                                   |
| character_set_database   | utf8                                   |
| character_set_filesystem | binary                                 |
| character_set_results    | utf8                                   |
| character_set_server     | utf8                                   |
| character_set_system     | utf8                                   |
| character_sets_dir       | /usr/local/mysql/share/mysql/charsets/ |
+--------------------------+----------------------------------------+

after grant super:
mysql -u uswer -p --host 10.24.20.100 -e "show variables like '%char%';"
Enter password: 
+--------------------------+----------------------------------------+
| Variable_name            | Value                                  |
+--------------------------+----------------------------------------+
| character_set_client     | latin2                                 |
| character_set_connection | latin2                                 |
| character_set_database   | utf8                                   |
| character_set_filesystem | binary                                 |
| character_set_results    | latin2                                 |
| character_set_server     | utf8                                   |
| character_set_system     | utf8                                   |
| character_sets_dir       | /usr/local/mysql/share/mysql/charsets/ |
+--------------------------+----------------------------------------+

How to repeat:
grant / revoke super privileges on regular user
[28 Jan 2011 10:42] Peter Laursen
I can't reproduce in 5.1.54 on Windows:

mysql> SHOW VARIABLES LIKE 'character_set_client';
+----------------------+-------+
| Variable_name        | Value |
+----------------------+-------+
| character_set_client | utf8  |
+----------------------+-------+
1 row in set (0.00 sec)

mysql> CREATE USER 'sup'@'localhost';
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT SUPER ON *.* TO 'sup'@'localhost';
Query OK, 0 rows affected (0.00 sec)

mysql> SHOW VARIABLES LIKE 'character_set_client';
+----------------------+-------+
| Variable_name        | Value |
+----------------------+-------+
| character_set_client | utf8  |
+----------------------+-------+
1 row in set (0.00 sec)

mysql>

Peter
(not a MySQL person)
[28 Jan 2011 11:03] Valeriy Kravchuk
I also can not repeat this with 5.1.54:

C:\Program Files\MySQL\MySQL Server 5.1\bin>mysql -uroot -proot -P3310 test
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 34
Server version: 5.1.54-community MySQL Community Server (GPL)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create user uswer;
Query OK, 0 rows affected (0.13 sec)

mysql> grant select on *.* to uswer;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

C:\Program Files\MySQL\MySQL Server 5.1\bin>mysql -uuswer -e "select current_use
r()"
+----------------+
| current_user() |
+----------------+
| uswer@%        |
+----------------+

C:\Program Files\MySQL\MySQL Server 5.1\bin>mysql -uuswer -e "show variables lik
e 'char%'"
+--------------------------+----------------------------------------------------
-----+
| Variable_name            | Value
     |
+--------------------------+----------------------------------------------------
-----+
| character_set_client     | utf8
     |
| character_set_connection | utf8
     |
| character_set_database   | utf8
     |
| character_set_filesystem | binary
     |
| character_set_results    | utf8
     |
| character_set_server     | utf8
     |
| character_set_system     | utf8
     |
| character_sets_dir       | C:\Program Files\MySQL\MySQL Server 5.1\share\chars
ets\ |
+--------------------------+----------------------------------------------------
-----+

C:\Program Files\MySQL\MySQL Server 5.1\bin>mysql -uroot -proot -P3310 test
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 37
Server version: 5.1.54-community MySQL Community Server (GPL)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> grant super on *.* to uswer;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

C:\Program Files\MySQL\MySQL Server 5.1\bin>mysql -uuswer -e "show grants"
+-------------------------------------------+
| Grants for uswer@%                        |
+-------------------------------------------+
| GRANT SELECT, SUPER ON *.* TO 'uswer'@'%' |
+-------------------------------------------+

C:\Program Files\MySQL\MySQL Server 5.1\bin>mysql -uuswer -e "show variables lik
e 'char%'"
+--------------------------+----------------------------------------------------
-----+
| Variable_name            | Value
     |
+--------------------------+----------------------------------------------------
-----+
| character_set_client     | utf8
     |
| character_set_connection | utf8
     |
| character_set_database   | utf8
     |
| character_set_filesystem | binary
     |
| character_set_results    | utf8
     |
| character_set_server     | utf8
     |
| character_set_system     | utf8
     |
| character_sets_dir       | C:\Program Files\MySQL\MySQL Server 5.1\share\chars
ets\ |
+--------------------------+----------------------------------------------------
-----+
[28 Jan 2011 11:16] Peter Laursen
I think it may depend on the default character setting in configuration! @Artur: do you have latin2 here? 

I could imagine the scenario:
1) latin* as default character setting in configuration.
2) non-root user connects and does SET NAMES UTF8 immediately after connection.
3) root grants SUPER to non-root user .. and client charset changes for him.
.. If this or something like this happens it is very serious as INSERTS of non-ASCII characters will garble.

(and I now understand my mistake: It is not the root user that is affected but the 'other user')
[28 Jan 2011 11:46] MySQL Verification Team
my guess would be that you have an "init-connect" option somewhere.
always run : mysql --no-defaults to skip reading my.ini files totally
[28 Jan 2011 12:48] Artur Wosinski
@Peter Laursen: I have "init-connect='SET NAMES utf8'" i my [mysqld] section of server`s my.ini. 
server was build with --with-charset=utf8 and --with-extra-charsets=complex

I have no other settings in server` my.ini file

I`m launching the same mysql binary and connect to one mysql server. 
only thing I change is privilege "super"... 

Maybe the "super" privilege bypassess execution of "init-connect" ?

--no-defaults on client does not changes anything:
silver:~$ mysql --no-defaults -u test -ptest --host 10.24.20.100 -e "show variables like '%char%';"
+--------------------------+----------------------------------------+
| Variable_name            | Value                                  |
+--------------------------+----------------------------------------+
| character_set_client     | utf8                                   |
| character_set_connection | utf8                                   |
| character_set_database   | utf8                                   |
| character_set_filesystem | binary                                 |
| character_set_results    | utf8                                   |
| character_set_server     | utf8                                   |
| character_set_system     | utf8                                   |
| character_sets_dir       | /usr/local/mysql/share/mysql/charsets/ |
+--------------------------+----------------------------------------+
silver:~$ mysql -v -u root -p  --host 10.24.20.100 -e  "GRANT SUPER ON * . * TO 'test'@'%';"
Enter password: 
--------------
GRANT SUPER ON * . * TO 'test'@'%'
--------------

silver:~$ mysql --no-defaults -u test -ptest --host 10.24.20.100 -e "show variables like '%char%';"
+--------------------------+----------------------------------------+
| Variable_name            | Value                                  |
+--------------------------+----------------------------------------+
| character_set_client     | latin1                                 |
| character_set_connection | latin1                                 |
| character_set_database   | utf8                                   |
| character_set_filesystem | binary                                 |
| character_set_results    | latin1                                 |
| character_set_server     | utf8                                   |
| character_set_system     | utf8                                   |
| character_sets_dir       | /usr/local/mysql/share/mysql/charsets/ |
+--------------------------+----------------------------------------+
[28 Jan 2011 12:57] Peter Laursen
1) I think you should share the complete my.ini/my.cnf

2) It is not clear to me if user has to reconnect or not in order to see this happen?
[28 Jan 2011 13:29] Artur Wosinski
@Peter: I think, I know, where the problem is:

When:
1. mysql client has default charset "latin1"
2. mysqld has "init-connect='SET NAMES utf8'" in my.ini
3. user has "super" privilege
then execution of init-connect commands is bypassed.
[28 Jan 2011 13:41] Peter Laursen
hmmm .. I never used 'init_connect' constructions myself and don't know much about it. I always SET NAMES from the client when I connect.

I also think that as this is now categorized as 'Can't repeat' you cannot change to 'Open'? Let's hope that Valeriy or Shane considers your last post.
[28 Jan 2011 13:45] Valeriy Kravchuk
Then this is explained by http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html#sysvar_init_connect and, thus, is not a bug.
[28 Jan 2011 13:57] Artur Wosinski
I see this now.. 
shame on me. :|