Skip to content

Commit b4104b2

Browse files
MarkLeithbjornmu
authored andcommitted
Bug#21938432 MYSQL_UPGRADE 5.7.9 FAILS WITH ERROR ON MYSQL.SYS USER ON DUMP UPGRADE
* Two problems here: ** Now WITH_PERFSCHEMA_STORAGE_ENGINE is not set we were assuming the installed sys schema version was always 1.0.0, removed this now ** Also FLUSH PRIVILEGES after creating the user, so it is available straight away Bug#21935210 MYSQL.SYS@LOCALHOST HAS TRIGGER PRIVILEGE ON THE WHOLE INSTANCE * Removed global TRIGGER, and added only on the sys schema Bug#21966366 SYS: PROVIDE A WAY TO ALLOW FOR LOCAL CUSTOMISATIONS * Rather than check for equality of counts, check for at least as many as expected (but allow more or equal) Sneak in a typo fix (s/procdure/procedure/) in the execute_prepared_stmt comment. Reviewed-by: Georgi Kodinov <[email protected]> Reviewed-by: Marc Alff <[email protected]> RB: 10567 (cherry picked from commit dde827eccabfc5d8954977d0251b7dba3cce8342)
1 parent cb9ee0c commit b4104b2

File tree

6 files changed

+21
-19
lines changed

6 files changed

+21
-19
lines changed

client/upgrade/program.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,14 @@ class Program : public Base::Abstract_connection_program
250250

251251
while ((row = mysql_fetch_row(result)))
252252
{
253-
ulong sys_version = calc_server_version(row[0]);
254-
if (sys_version >= calc_server_version(SYS_SCHEMA_VERSION))
253+
stringstream ss;
254+
ulong installed_sys_version = calc_server_version(row[0]);
255+
ulong expected_sys_version = calc_server_version(SYS_SCHEMA_VERSION);
256+
if (installed_sys_version >= expected_sys_version)
255257
{
256-
stringstream ss;
257258
ss << "The sys schema is already up to date (version " << row[0] << ").";
258259
this->print_verbose_message(ss.str());
259260
} else {
260-
stringstream ss;
261261
ss << "Found outdated sys schema version " << row[0] << ".";
262262
this->print_verbose_message(ss.str());
263263
if (this->run_sys_schema_upgrade() != 0)
@@ -294,7 +294,7 @@ class Program : public Base::Abstract_connection_program
294294

295295
while ((row = mysql_fetch_row(result)))
296296
{
297-
if (SYS_TABLE_COUNT != atoi(row[0]))
297+
if (SYS_TABLE_COUNT > atoi(row[0]))
298298
{
299299
stringstream ss;
300300
ss << "Found " << row[0] << " sys tables, but expected " << SYS_TABLE_COUNT << "."
@@ -324,7 +324,7 @@ class Program : public Base::Abstract_connection_program
324324

325325
while ((row = mysql_fetch_row(result)))
326326
{
327-
if (SYS_VIEW_COUNT != atoi(row[0]))
327+
if (SYS_VIEW_COUNT > atoi(row[0]))
328328
{
329329
stringstream ss;
330330
ss << "Found " << row[0] << " sys views, but expected " << SYS_VIEW_COUNT << "."
@@ -354,7 +354,7 @@ class Program : public Base::Abstract_connection_program
354354

355355
while ((row = mysql_fetch_row(result)))
356356
{
357-
if (SYS_TRIGGER_COUNT != atoi(row[0]))
357+
if (SYS_TRIGGER_COUNT > atoi(row[0]))
358358
{
359359
stringstream ss;
360360
ss << "Found " << row[0] << " sys triggers, but expected " << SYS_TRIGGER_COUNT << "."
@@ -384,7 +384,7 @@ class Program : public Base::Abstract_connection_program
384384

385385
while ((row = mysql_fetch_row(result)))
386386
{
387-
if (SYS_FUNCTION_COUNT != atoi(row[0]))
387+
if (SYS_FUNCTION_COUNT > atoi(row[0]))
388388
{
389389
stringstream ss;
390390
ss << "Found " << row[0] << " sys functions, but expected " << SYS_FUNCTION_COUNT << "."
@@ -414,7 +414,7 @@ class Program : public Base::Abstract_connection_program
414414

415415
while ((row = mysql_fetch_row(result)))
416416
{
417-
if (SYS_PROCEDURE_COUNT != atoi(row[0]))
417+
if (SYS_PROCEDURE_COUNT > atoi(row[0]))
418418
{
419419
stringstream ss;
420420
ss << "Found " << row[0] << " sys procedures, but expected " << SYS_PROCEDURE_COUNT << "."

cmake/mysql_version.cmake

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,9 @@ ENDIF()
101101
# Get the sys schema version from the mysql_sys_schema.sql file
102102
# however if compiling without performance schema, always use version 1.0.0
103103
MACRO(GET_SYS_SCHEMA_VERSION)
104-
IF(NOT WITH_PERFSCHEMA_STORAGE_ENGINE)
105-
SET(SYS_SCHEMA_VERSION "1.0.0")
106-
ELSE()
107-
FILE (STRINGS ${CMAKE_SOURCE_DIR}/scripts/mysql_sys_schema.sql str REGEX "SELECT \\'([0-9]+\\.[0-9]+\\.[0-9]+)\\' AS")
108-
IF(str)
109-
STRING(REGEX MATCH "([0-9]+\\.[0-9]+\\.[0-9]+)" SYS_SCHEMA_VERSION "${str}")
110-
ENDIF()
104+
FILE (STRINGS ${CMAKE_SOURCE_DIR}/scripts/mysql_sys_schema.sql str REGEX "SELECT \\'([0-9]+\\.[0-9]+\\.[0-9]+)\\' AS sys_version")
105+
IF(str)
106+
STRING(REGEX MATCH "([0-9]+\\.[0-9]+\\.[0-9]+)" SYS_SCHEMA_VERSION "${str}")
111107
ENDIF()
112108
ENDMACRO()
113109

mysql-test/r/wl6443_deprecation.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ create view mysql.host as select HOST from mysql.db;
149149
create user 'wl6443_u1'@'10.10.10.1' identified by 'sql';
150150
select count(*) from mysql.host;
151151
count(*)
152-
2
152+
3
153153
mysql.columns_priv OK
154154
mysql.db OK
155155
mysql.engine_cost OK

mysql-test/suite/funcs_1/r/is_schema_privileges.result

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ IS_GRANTABLE varchar(3) NO
5252
SELECT GRANTEE, TABLE_CATALOG, TABLE_SCHEMA, PRIVILEGE_TYPE
5353
FROM information_schema.schema_privileges WHERE table_catalog IS NOT NULL;
5454
GRANTEE TABLE_CATALOG TABLE_SCHEMA PRIVILEGE_TYPE
55+
'mysql.sys'@'localhost' def sys TRIGGER
5556
''@'%' def test SELECT
5657
''@'%' def test INSERT
5758
''@'%' def test UPDATE

mysql-test/suite/perfschema/r/privilege_table_io.result

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ wait/io/table/sql/handler handler.cc: TABLE mysql user fetch 1
119119
wait/io/table/sql/handler handler.cc: TABLE mysql db fetch 1
120120
wait/io/table/sql/handler handler.cc: TABLE mysql db fetch 1
121121
wait/io/table/sql/handler handler.cc: TABLE mysql db fetch 1
122+
wait/io/table/sql/handler handler.cc: TABLE mysql db fetch 1
122123
wait/io/table/sql/handler handler.cc: TABLE mysql proxies_priv fetch 1
123124
wait/io/table/sql/handler handler.cc: TABLE mysql proxies_priv fetch 1
124125
wait/io/table/sql/handler handler.cc: TABLE mysql proxies_priv fetch 1

scripts/mysql_sys_schema.sql

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@
1818
-- PLEASE SUBMIT A PULL REQUEST TO https://github.com/MarkLeith/mysql-sys
1919
--
2020

21-
REPLACE INTO mysql.user VALUES ('localhost','mysql.sys','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','Y','N','','','','',0,0,0,0,'mysql_native_password','*THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE','N',CURRENT_TIMESTAMP,NULL,'Y');
21+
REPLACE INTO mysql.user VALUES ('localhost','mysql.sys','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','','','','',0,0,0,0,'mysql_native_password','*THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE','N',CURRENT_TIMESTAMP,NULL,'Y');
22+
23+
REPLACE INTO mysql.db VALUES ('localhost','sys','mysql.sys','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','Y');
2224

2325
REPLACE INTO mysql.tables_priv VALUES ('localhost','sys','mysql.sys','sys_config','root@localhost', CURRENT_TIMESTAMP, 'Select', '');
2426

27+
FLUSH PRIVILEGES;
28+
2529
SET NAMES utf8;
2630

2731
CREATE DATABASE IF NOT EXISTS sys DEFAULT CHARACTER SET utf8;
@@ -330,7 +334,7 @@ CREATE DEFINER='mysql.sys'@'localhost' PROCEDURE create_synonym_db ( IN in_db_na
330334

331335
DROP PROCEDURE IF EXISTS execute_prepared_stmt;
332336

333-
CREATE DEFINER='mysql.sys'@'localhost' PROCEDURE execute_prepared_stmt ( IN in_query longtext CHARACTER SET UTF8 ) COMMENT '\n Description\n \n Takes the query in the argument and executes it using a prepared statement. The prepared statement is deallocated,\n so the procdure is mainly useful for executing one off dynamically created queries.\n \n The sys_execute_prepared_stmt prepared statement name is used for the query and is required not to exist.\n \n \n Parameters\n \n in_query (longtext CHARACTER SET UTF8):\n The query to execute.\n \n \n Configuration Options\n \n sys.debug\n Whether to provide debugging output.\n Default is ''OFF''. Set to ''ON'' to include.\n \n \n Example\n \n mysql> CALL sys.execute_prepared_stmt(''SELECT * FROM sys.sys_config'');\n +------------------------+-------+---------------------+--------+\n | variable | value | set_time | set_by |\n +------------------------+-------+---------------------+--------+\n | statement_truncate_len | 64 | 2015-06-30 13:06:00 | NULL |\n +------------------------+-------+---------------------+--------+\n 1 row in set (0.00 sec)\n \n Query OK, 0 rows affected (0.00 sec)\n ' SQL SECURITY INVOKER NOT DETERMINISTIC READS SQL DATA BEGIN IF (@sys.debug IS NULL) THEN SET @sys.debug = sys.sys_get_config('debug', 'OFF'); END IF; IF (in_query IS NULL OR LENGTH(in_query) < 4) THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = "The @sys.execute_prepared_stmt.sql must contain a query"; END IF; SET @sys.execute_prepared_stmt.sql = in_query; IF (@sys.debug = 'ON') THEN SELECT @sys.execute_prepared_stmt.sql AS 'Debug'; END IF; PREPARE sys_execute_prepared_stmt FROM @sys.execute_prepared_stmt.sql; EXECUTE sys_execute_prepared_stmt; DEALLOCATE PREPARE sys_execute_prepared_stmt; SET @sys.execute_prepared_stmt.sql = NULL; END;
337+
CREATE DEFINER='mysql.sys'@'localhost' PROCEDURE execute_prepared_stmt ( IN in_query longtext CHARACTER SET UTF8 ) COMMENT '\n Description\n \n Takes the query in the argument and executes it using a prepared statement. The prepared statement is deallocated,\n so the procedure is mainly useful for executing one off dynamically created queries.\n \n The sys_execute_prepared_stmt prepared statement name is used for the query and is required not to exist.\n \n \n Parameters\n \n in_query (longtext CHARACTER SET UTF8):\n The query to execute.\n \n \n Configuration Options\n \n sys.debug\n Whether to provide debugging output.\n Default is ''OFF''. Set to ''ON'' to include.\n \n \n Example\n \n mysql> CALL sys.execute_prepared_stmt(''SELECT * FROM sys.sys_config'');\n +------------------------+-------+---------------------+--------+\n | variable | value | set_time | set_by |\n +------------------------+-------+---------------------+--------+\n | statement_truncate_len | 64 | 2015-06-30 13:06:00 | NULL |\n +------------------------+-------+---------------------+--------+\n 1 row in set (0.00 sec)\n \n Query OK, 0 rows affected (0.00 sec)\n ' SQL SECURITY INVOKER NOT DETERMINISTIC READS SQL DATA BEGIN IF (@sys.debug IS NULL) THEN SET @sys.debug = sys.sys_get_config('debug', 'OFF'); END IF; IF (in_query IS NULL OR LENGTH(in_query) < 4) THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = "The @sys.execute_prepared_stmt.sql must contain a query"; END IF; SET @sys.execute_prepared_stmt.sql = in_query; IF (@sys.debug = 'ON') THEN SELECT @sys.execute_prepared_stmt.sql AS 'Debug'; END IF; PREPARE sys_execute_prepared_stmt FROM @sys.execute_prepared_stmt.sql; EXECUTE sys_execute_prepared_stmt; DEALLOCATE PREPARE sys_execute_prepared_stmt; SET @sys.execute_prepared_stmt.sql = NULL; END;
334338

335339
DROP PROCEDURE IF EXISTS diagnostics;
336340

0 commit comments

Comments
 (0)