Skip to content
/ server Public

Commit c086a2c

Browse files
committed
MDEV-38698 mysql_upgrade does not fix charset and collation for mysql.user
In case if the view mysql.user was created (e.g. in 10.6) with a pre- 18edb09 server with an unexpected character_set_client and collation_connection, e.g. utf8mb3 and utf8mb3_general_ci, mysql_upgrade did not fix it to the expected latin1 and latin1_swedish_ci. Since 11.8 this could often lead to "Illegax mix of collations" errors when querying mysql.user, because since 11.8 the default collation for utf8mb3 is utf8mb3_uca1400_ai_ci, according to the default @@character_set_collations. For example: MariaDB [test]> select user,host,is_role from -> mysql.user where is_role='N'; ERROR 1267 (HY000): Illegal mix of collations (utf8mb3_general_ci,COERCIBLE) and (utf8mb3_uca1400_ai_ci,COERCIBLE) for operation '=' Fixing mariadb_system_tables.sql to drop the view if it has non-standard character set or collations, so it gets recreated again correctly.
1 parent 01ff5ae commit c086a2c

File tree

4 files changed

+75
-0
lines changed

4 files changed

+75
-0
lines changed

mysql-test/main/mysql_upgrade.result

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2453,3 +2453,18 @@ GRANT USAGE ON *.* TO `foo`@`bar`
24532453
GRANT ALL PRIVILEGES ON `mysql`.* TO `foo`@`bar`
24542454
drop user foo@bar;
24552455
# End of 11.3 tests
2456+
#
2457+
# MDEV-38698 mysql_upgrade does not fix charset and collation for mysql.user
2458+
#
2459+
FLUSH TABLES mysql.user;
2460+
FLUSH PRIVILEGES;
2461+
SELECT CHARACTER_SET_CLIENT, COLLATION_CONNECTION FROM INFORMATION_SCHEMA.VIEWS
2462+
WHERE TABLE_SCHEMA='mysql' AND TABLE_NAME='user';
2463+
CHARACTER_SET_CLIENT COLLATION_CONNECTION
2464+
utf8mb3 utf8mb3_general_ci
2465+
FLUSH TABLES mysql.user;
2466+
FLUSH PRIVILEGES;
2467+
SELECT CHARACTER_SET_CLIENT, COLLATION_CONNECTION FROM INFORMATION_SCHEMA.VIEWS
2468+
WHERE TABLE_SCHEMA='mysql' AND TABLE_NAME='user';
2469+
CHARACTER_SET_CLIENT COLLATION_CONNECTION
2470+
latin1 latin1_swedish_ci

mysql-test/main/mysql_upgrade.test

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,3 +573,25 @@ show grants for foo@bar;
573573
drop user foo@bar;
574574

575575
--echo # End of 11.3 tests
576+
577+
578+
--echo #
579+
--echo # MDEV-38698 mysql_upgrade does not fix charset and collation for mysql.user
580+
--echo #
581+
582+
--remove_file $MYSQLD_DATADIR/mysql/user.frm
583+
--copy_file std_data/upgrade/user-100625-utf8mb3.frm $MYSQLD_DATADIR/mysql/user.frm
584+
585+
FLUSH TABLES mysql.user;
586+
FLUSH PRIVILEGES;
587+
SELECT CHARACTER_SET_CLIENT, COLLATION_CONNECTION FROM INFORMATION_SCHEMA.VIEWS
588+
WHERE TABLE_SCHEMA='mysql' AND TABLE_NAME='user';
589+
590+
--replace_result $MYSQLTEST_VARDIR var
591+
--exec $MYSQL_UPGRADE --force --silent 2>&1
592+
--remove_file $MYSQLD_DATADIR/mariadb_upgrade_info
593+
594+
FLUSH TABLES mysql.user;
595+
FLUSH PRIVILEGES;
596+
SELECT CHARACTER_SET_CLIENT, COLLATION_CONNECTION FROM INFORMATION_SCHEMA.VIEWS
597+
WHERE TABLE_SCHEMA='mysql' AND TABLE_NAME='user';

mysql-test/std_data/upgrade/user-100625-utf8mb3.frm

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/mariadb_system_tables.sql

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,28 @@ INSERT INTO tmp_user_sys (Host,User,Priv) VALUES ('localhost','mariadb.sys','{"a
4848
INSERT IGNORE INTO global_priv SELECT * FROM tmp_user_sys WHERE 0 <> @need_sys_user_creation;
4949
DROP TABLE tmp_user_sys;
5050

51+
52+
-- Drop mysql.user if it has wrong
53+
-- character_set_client or collation_connection
54+
DELIMITER $$
55+
BEGIN NOT ATOMIC
56+
DECLARE v0 ROW TYPE OF INFORMATION_SCHEMA.VIEWS;
57+
SET v0= (SELECT * FROM INFORMATION_SCHEMA.VIEWS
58+
WHERE TABLE_CATALOG='def'
59+
AND TABLE_SCHEMA='mysql'
60+
AND TABLE_NAME='user');
61+
-- Drop only if the DEFINER is standard
62+
IF v0.DEFINER='mariadb.sys@localhost' AND
63+
(v0.CHARACTER_SET_CLIENT<>'latin1' OR
64+
v0.COLLATION_CONNECTION<>'latin1_swedish_ci')
65+
THEN
66+
DROP VIEW user;
67+
END IF;
68+
END
69+
$$
70+
DELIMITER ;
71+
72+
5173
CREATE DEFINER='mariadb.sys'@'localhost' SQL SECURITY DEFINER VIEW IF NOT EXISTS user AS SELECT
5274
Host,
5375
User,

0 commit comments

Comments
 (0)