|
| 1 | +# ==== Purpose ==== |
| 2 | +# |
| 3 | +# Verify that columns in the 'GRANT SELECT' statements |
| 4 | +# are properly quoted before writing to the binary log. |
| 5 | +# |
| 6 | +# ==== Implementation ==== |
| 7 | +# |
| 8 | +# 1. Initial setup on master. |
| 9 | +# 1.1 Create tables with reserved words as column names. |
| 10 | +# 1.2 Create users for granting column privileges. |
| 11 | +# 2. With sql_mode='ANSI_QUOTES', execute GRANT SELECT commands on master. |
| 12 | +# 3. With sql_mode='', execute GRANT SELECT commands on master. |
| 13 | +# 4. Verify the correctness of 'GRANT SELECT' statement by printing |
| 14 | +# the binlog entry for the statement. |
| 15 | +# 5. Sync the slave with master. |
| 16 | +# 6. Verify that there is no difference in the column privileges |
| 17 | +# tables of master and slave. |
| 18 | +# |
| 19 | +# ==== References ==== |
| 20 | +# |
| 21 | +# Bug#28643405: LAST_ERROR_NUMBER: 1064 DURING GRANT SELECT |
| 22 | +# |
| 23 | + |
| 24 | +--source include/have_binlog_format_statement.inc |
| 25 | +--source include/master-slave.inc |
| 26 | + |
| 27 | +--echo |
| 28 | +--echo # 1. Initial setup on master. |
| 29 | +--echo # 1.1 Create tables with reserved words as column names. |
| 30 | +CREATE DATABASE `order`; |
| 31 | +CREATE TABLE `order`.`order` (`order` INT); |
| 32 | + |
| 33 | +CREATE DATABASE `column`; |
| 34 | +CREATE TABLE `column`.`column` (`column` INT); |
| 35 | + |
| 36 | +CREATE DATABASE `all`; |
| 37 | +CREATE TABLE `all`.`all`( |
| 38 | + id int NOT NULL PRIMARY KEY, |
| 39 | + item int, |
| 40 | + `table` varchar(10), |
| 41 | + `regexp` varchar(10)); |
| 42 | + |
| 43 | +--echo |
| 44 | +--echo # 1.2 Create users for granting column privileges. |
| 45 | +CREATE USER `order` IDENTIFIED BY 'password1'; |
| 46 | +CREATE USER `column` IDENTIFIED BY 'password2'; |
| 47 | +CREATE USER `all` IDENTIFIED BY 'password3'; |
| 48 | + |
| 49 | +--echo |
| 50 | +--echo # 2. With sql_mode='ANSI_QUOTES', execute GRANT SELECT commands on master. |
| 51 | + |
| 52 | +# Setting sql_mode to ANSI_QUOTES before executing GRANT. |
| 53 | +# ANSI_QUOTES mode will make sure the "(double quote) is used |
| 54 | +# as the identifier quote character while writing to the binlog. |
| 55 | +# This mode treats "(double quotes) as an identifier quote character |
| 56 | +# and not as a string quote character. |
| 57 | +SET @saved_sql_mode= @@session.sql_mode; |
| 58 | +SET SESSION sql_mode= 'ANSI_QUOTES'; |
| 59 | + |
| 60 | +# Save master position |
| 61 | +--let $binlog_start= query_get_value('SHOW MASTER STATUS', Position, 1) |
| 62 | + |
| 63 | +--echo |
| 64 | +--echo # Execute GRANT SELECT commands on master. |
| 65 | + |
| 66 | +# Columns having reserved words |
| 67 | +GRANT SELECT(`order`) ON `order`.`order` TO `order`; |
| 68 | + |
| 69 | +# Column names having both reserved words and non-reserved words |
| 70 | +GRANT SELECT(id,`table`) ON `all`.`all` TO `all`; |
| 71 | + |
| 72 | +--echo |
| 73 | +--echo # Verify the correctness of 'GRANT SELECT' statement by printing |
| 74 | +--echo # the binlog entry for the statement. |
| 75 | +--source include/show_binlog_events.inc |
| 76 | + |
| 77 | +--echo |
| 78 | +--echo # 3. With sql_mode='', execute GRANT SELECT commands on master. |
| 79 | + |
| 80 | +# Reseting sql_mode. This will make sure `(backtick) is used as |
| 81 | +# the identifier quote character while writing to the binlog. |
| 82 | +SET SESSION sql_mode= ''; |
| 83 | + |
| 84 | +# Update master position |
| 85 | +--let $binlog_start= query_get_value('SHOW MASTER STATUS', Position, 1) |
| 86 | + |
| 87 | +--echo |
| 88 | +--echo # Execute GRANT SELECT commands on master. |
| 89 | + |
| 90 | +# Columns having reserved words |
| 91 | +GRANT SELECT(`column`) ON `column`.`column` TO `column`; |
| 92 | + |
| 93 | +# Column names having both reserved words and non-reserved words |
| 94 | +GRANT SELECT(item,`regexp`) ON `all`.`all` TO `all`; |
| 95 | + |
| 96 | +--echo |
| 97 | +--echo # 4. Verify the correctness of 'GRANT SELECT' statement by printing |
| 98 | +--echo # the binlog entry for the statement. |
| 99 | +--source include/show_binlog_events.inc |
| 100 | + |
| 101 | +--echo |
| 102 | +--echo # 5. Sync the slave with master. |
| 103 | +--source include/sync_slave_sql_with_master.inc |
| 104 | + |
| 105 | +--echo |
| 106 | +--echo # 6. Verify that there is no difference in the column privileges |
| 107 | +--echo # tables of master and slave. |
| 108 | +--source include/rpl_connection_master.inc |
| 109 | +--let diff_tables=master:mysql.columns_priv, slave:mysql.columns_priv |
| 110 | +--source include/diff_tables.inc |
| 111 | + |
| 112 | +# Cleanup |
| 113 | +SET SESSION sql_mode= @saved_sql_mode; |
| 114 | +DROP USER `order`,`column`,`all`; |
| 115 | +DROP DATABASE `order`; |
| 116 | +DROP DATABASE `column`; |
| 117 | +DROP DATABASE `all`; |
| 118 | +--source include/rpl_end.inc |
0 commit comments