Skip to content

Commit 66b0ea5

Browse files
author
Anushree Prakash B
committed
Bug#25813089 - CREATE USER IF NOT EXISTS SHOULD ALWAYS BE
WRITTEN TO THE BINLOGS DESCRIPTION =========== MySQL 5.7 introduced a new command CREATE USER IF NOT EXISTS ... The idea of this command is that it can be run safely on a master and would not break things irrespective of whether the user exists on the master or on the slave. However, the implementation does not write this statement to the binlog when the user exists on the master which results in an inconsistency. ANALYSIS ======== Presently, if the statements CREATE USER IF NOT EXISTS are a no-op on the master, they are not written to the the binlog. This results in an inconsistent behavior if a particular user is present on the slave but not on the master. Similar issue arises for ALTER USER IF EXISTS statements. FIX === The fix ensures that the statements having queries like 1. CREATE USER IF NOT EXISTS .. and 2. ALTER USER IF EXISTS .. are binlogged making sure that replication does not break and the consistency is maintained across all masters and slaves.
1 parent bfed7d5 commit 66b0ea5

9 files changed

+375
-57
lines changed

mysql-test/r/user_if_exists.result

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
call mtr.add_suppression('Corresponding entry in binary log used default authentication.*');
12
DELETE FROM mysql.user WHERE user = 'wl8540';
23
FLUSH PRIVILEGES;
34
SELECT COUNT(*) FROM mysql.user WHERE user = 'wl8540';
@@ -163,6 +164,7 @@ Level Code Message
163164
SELECT COUNT(*) FROM mysql.user WHERE user = 'wl8540';
164165
COUNT(*)
165166
3
167+
# Search warnings in the server log
166168
DELETE FROM mysql.user WHERE user = 'wl8540';
167169
FLUSH PRIVILEGES;
168170

@@ -266,4 +268,5 @@ DROP USER b21807286@localhost;
266268
ALTER USER IF EXISTS b21807286@localhost IDENTIFIED BY 'xyz';
267269
Warnings:
268270
Note 3162 User 'b21807286'@'localhost' does not exist.
271+
# Search warnings in the server log
269272
# End of 5.7 tests

mysql-test/suite/binlog/r/binlog_user_if_exists.result

+119-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
call mtr.add_suppression('Corresponding entry in binary log used default authentication.*');
12
include/master-slave.inc
23
Warnings:
34
Note #### Sending passwords in plain text without SSL/TLS is extremely insecure.
@@ -33,13 +34,130 @@ include/sync_slave_sql_with_master.inc
3334
include/show_binlog_events.inc
3435
Log_name Pos Event_type Server_id End_log_pos Info
3536
slave-bin.000001 # Query # # use `test`; CREATE USER 'u1'@'localhost' IDENTIFIED WITH 'mysql_native_password'
36-
slave-bin.000001 # Query # # use `test`; CREATE USER IF NOT EXISTS 'u2'@'localhost' IDENTIFIED WITH 'mysql_native_password'
37+
slave-bin.000001 # Query # # use `test`; CREATE USER IF NOT EXISTS 'u1'@'localhost' IDENTIFIED WITH 'mysql_native_password','u2'@'localhost' IDENTIFIED WITH 'mysql_native_password'
3738
slave-bin.000001 # Query # # use `test`; ALTER USER IF EXISTS 'u1'@'localhost' ACCOUNT LOCK
3839
slave-bin.000001 # Query # # use `test`; DROP USER u1@localhost
3940
slave-bin.000001 # Query # # use `test`; DROP USER IF EXISTS u2@localhost
4041
slave-bin.000001 # Query # # use `test`; CREATE USER IF NOT EXISTS 'b21807286'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*85D0F19E5598AC04AC7B3FCF5383247D28FB59EF'
42+
slave-bin.000001 # Query # # use `test`; CREATE USER IF NOT EXISTS 'b21807286'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*CF18BC9B45678165F755356FBD148E0F84D19A63'
4143
slave-bin.000001 # Query # # use `test`; ALTER USER IF EXISTS 'b21807286'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*7B8BEAA4240FE1A214BFAEDD99FB3842E4234E5E'
44+
slave-bin.000001 # Query # # use `test`; ALTER USER IF EXISTS 'b21807286_not_exists'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*498D18FA98FB65CF8E71D1D9DA5721646499DBD1'
4245
slave-bin.000001 # Query # # use `test`; DROP USER b21807286@localhost
46+
#
47+
# Bug #25813089: "CREATE USER IF NOT EXISTS SHOULD ALWAYS
48+
# BE WRITTEN TO THE BINLOGS"
49+
#
50+
# ------
51+
"Scenario 1: CREATE/ALTER USER IF[NOT]EXISTS FOR A SINGLE USER"
52+
# ------
53+
CREATE USER u1@localhost IDENTIFIED BY 'pass1';
54+
CREATE USER IF NOT EXISTS u1@localhost IDENTIFIED BY 'pass2';
55+
Warnings:
56+
Note 3163 User 'u1'@'localhost' already exists.
57+
ALTER USER u1@localhost IDENTIFIED BY 'pass3';
58+
ALTER USER IF EXISTS u1@localhost IDENTIFIED BY 'pass4';
59+
ALTER USER IF EXISTS u1_not_exists@localhost IDENTIFIED BY 'pass5';
60+
Warnings:
61+
Note 3162 User 'u1_not_exists'@'localhost' does not exist.
62+
DROP USER u1@localhost;
63+
[On Master]
64+
include/show_binlog_events.inc
65+
Log_name Pos Event_type Server_id End_log_pos Info
66+
master-bin.000001 # Query # # use `test`; CREATE USER 'u1'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*22A99BA288DB55E8E230679259740873101CD636'
67+
master-bin.000001 # Query # # use `test`; CREATE USER IF NOT EXISTS 'u1'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*1B884EF334D678B0743C8CE0425F980669D8FBB6'
68+
master-bin.000001 # Query # # use `test`; ALTER USER 'u1'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*35B5E90BC4F5AE5D02ED515DF6B61141F24EDA02'
69+
master-bin.000001 # Query # # use `test`; ALTER USER IF EXISTS 'u1'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*B718D8767BBACFBCE02BA2669ECCEB05930FF7D7'
70+
master-bin.000001 # Query # # use `test`; ALTER USER IF EXISTS 'u1_not_exists'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*9D3D6FA96FA91117D387A4B990C41F5809A536EE'
71+
master-bin.000001 # Query # # use `test`; DROP USER u1@localhost
72+
include/sync_slave_sql_with_master.inc
73+
[On Slave]
74+
include/show_binlog_events.inc
75+
Log_name Pos Event_type Server_id End_log_pos Info
76+
slave-bin.000001 # Query # # use `test`; CREATE USER 'u1'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*22A99BA288DB55E8E230679259740873101CD636'
77+
slave-bin.000001 # Query # # use `test`; CREATE USER IF NOT EXISTS 'u1'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*1B884EF334D678B0743C8CE0425F980669D8FBB6'
78+
slave-bin.000001 # Query # # use `test`; ALTER USER 'u1'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*35B5E90BC4F5AE5D02ED515DF6B61141F24EDA02'
79+
slave-bin.000001 # Query # # use `test`; ALTER USER IF EXISTS 'u1'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*B718D8767BBACFBCE02BA2669ECCEB05930FF7D7'
80+
slave-bin.000001 # Query # # use `test`; ALTER USER IF EXISTS 'u1_not_exists'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*9D3D6FA96FA91117D387A4B990C41F5809A536EE'
81+
slave-bin.000001 # Query # # use `test`; DROP USER u1@localhost
82+
"Creating a user only on slave"
83+
CREATE USER IF NOT EXISTS slave_user@localhost IDENTIFIED BY 'slave_pass';
84+
# ------
85+
"Scenario 2: CREATE/ALTER USER IF[NOT]EXISTS FOR MULTIPLE USERS"
86+
# ------
87+
CREATE USER IF NOT EXISTS u1@localhost IDENTIFIED BY 'pass1',
88+
u2@localhost IDENTIFIED BY 'pass2';
89+
CREATE USER IF NOT EXISTS u1@localhost IDENTIFIED BY 'pass1',
90+
u2@localhost IDENTIFIED BY 'pass2',
91+
u3@localhost IDENTIFIED BY 'pass3';
92+
Warnings:
93+
Note 3163 User 'u1'@'localhost' already exists.
94+
Note 3163 User 'u2'@'localhost' already exists.
95+
ALTER USER IF EXISTS u1@localhost IDENTIFIED BY 'pass4',
96+
u2@localhost IDENTIFIED BY 'pass5',
97+
u3@localhost IDENTIFIED BY 'pass6',
98+
u4_not_exists@localhost IDENTIFIED BY 'pass7',
99+
slave_user@localhost IDENTIFIED BY 'pass8';
100+
Warnings:
101+
Note 3162 User 'u4_not_exists'@'localhost' does not exist.
102+
Note 3162 User 'slave_user'@'localhost' does not exist.
103+
DROP USER IF EXISTS u1@localhost, u2@localhost, u3@localhost, slave_user@localhost;
104+
Warnings:
105+
Note 3162 User 'slave_user'@'localhost' does not exist.
106+
[On Master]
107+
include/show_binlog_events.inc
108+
Log_name Pos Event_type Server_id End_log_pos Info
109+
master-bin.000001 # Query # # use `test`; CREATE USER IF NOT EXISTS 'u1'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*22A99BA288DB55E8E230679259740873101CD636','u2'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*1B884EF334D678B0743C8CE0425F980669D8FBB6'
110+
master-bin.000001 # Query # # use `test`; CREATE USER IF NOT EXISTS 'u1'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*22A99BA288DB55E8E230679259740873101CD636','u2'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*1B884EF334D678B0743C8CE0425F980669D8FBB6','u3'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*35B5E90BC4F5AE5D02ED515DF6B61141F24EDA02'
111+
master-bin.000001 # Query # # use `test`; ALTER USER IF EXISTS 'u1'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*B718D8767BBACFBCE02BA2669ECCEB05930FF7D7','u2'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*9D3D6FA96FA91117D387A4B990C41F5809A536EE','u3'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*E4744236E26ADD8C3C3D727C7851A097FBBB8A87','u4_not_exists'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*BEA19EBE4ACA6B1820BF580B4054EB6B5B0D198D','slave_user'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*F40D7E5342EC4960531243A96CC2E94079BC11B7'
112+
master-bin.000001 # Query # # use `test`; DROP USER IF EXISTS u1@localhost, u2@localhost, u3@localhost, slave_user@localhost
113+
include/sync_slave_sql_with_master.inc
114+
[On Slave]
115+
include/show_binlog_events.inc
116+
Log_name Pos Event_type Server_id End_log_pos Info
117+
slave-bin.000001 # Query # # use `test`; CREATE USER IF NOT EXISTS 'slave_user'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*A8204EFAFFB19DEF65BE70042A9D93F1971925BC'
118+
slave-bin.000001 # Query # # use `test`; CREATE USER IF NOT EXISTS 'u1'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*22A99BA288DB55E8E230679259740873101CD636','u2'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*1B884EF334D678B0743C8CE0425F980669D8FBB6'
119+
slave-bin.000001 # Query # # use `test`; CREATE USER IF NOT EXISTS 'u1'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*22A99BA288DB55E8E230679259740873101CD636','u2'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*1B884EF334D678B0743C8CE0425F980669D8FBB6','u3'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*35B5E90BC4F5AE5D02ED515DF6B61141F24EDA02'
120+
slave-bin.000001 # Query # # use `test`; ALTER USER IF EXISTS 'u1'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*B718D8767BBACFBCE02BA2669ECCEB05930FF7D7','u2'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*9D3D6FA96FA91117D387A4B990C41F5809A536EE','u3'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*E4744236E26ADD8C3C3D727C7851A097FBBB8A87','u4_not_exists'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*BEA19EBE4ACA6B1820BF580B4054EB6B5B0D198D','slave_user'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*F40D7E5342EC4960531243A96CC2E94079BC11B7'
121+
slave-bin.000001 # Query # # use `test`; DROP USER IF EXISTS u1@localhost, u2@localhost, u3@localhost, slave_user@localhost
122+
# ------
123+
"Scenario 3: CREATE/ALTER USER IF[NOT]EXISTS WITH"
124+
"AUTHENTICATION PLUGIN PROVIDED EXPLICITLY"
125+
# ------
126+
include/rpl_restart_server.inc [server_number=1 parameters: --default_authentication_plugin=sha256_password]
127+
include/rpl_reset.inc
128+
SHOW VARIABLES LIKE 'default_authentication_plugin';
129+
Variable_name Value
130+
default_authentication_plugin sha256_password
131+
CREATE USER IF NOT EXISTS u1@localhost IDENTIFIED WITH mysql_native_password by 'pass_native';
132+
CREATE USER IF NOT EXISTS u1@localhost IDENTIFIED WITH mysql_native_password by 'pass_native2';
133+
Warnings:
134+
Note 3163 User 'u1'@'localhost' already exists.
135+
ALTER USER IF EXISTS u1@localhost IDENTIFIED WITH mysql_native_password BY 'pass_native3';
136+
ALTER USER IF EXISTS u2_not_exists@localhost IDENTIFIED WITH mysql_native_password BY 'pass_native4';
137+
Warnings:
138+
Note 3162 User 'u2_not_exists'@'localhost' does not exist.
139+
SELECT user,authentication_string FROM mysql.user WHERE user='u1';
140+
user authentication_string
141+
u1 *52BA180A884483D54A3CEB45FB50D4E5B8071399
142+
DROP USER u1@localhost;
143+
[On Master]
144+
include/show_binlog_events.inc
145+
Log_name Pos Event_type Server_id End_log_pos Info
146+
master-bin.000001 # Query # # use `test`; CREATE USER IF NOT EXISTS 'u1'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*6DD89A65903AC3BCC4873BA43D17EFFB912C67EE'
147+
master-bin.000001 # Query # # use `test`; CREATE USER IF NOT EXISTS 'u1'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*AD3E6D897B165BF1FA7D3583FA1FF6AF31FA3C4B'
148+
master-bin.000001 # Query # # use `test`; ALTER USER IF EXISTS 'u1'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*52BA180A884483D54A3CEB45FB50D4E5B8071399'
149+
master-bin.000001 # Query # # use `test`; ALTER USER IF EXISTS 'u2_not_exists'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*53ED7183CBBC6D9995663DD96EFFA60E2CE2C96E'
150+
master-bin.000001 # Query # # use `test`; DROP USER u1@localhost
151+
include/sync_slave_sql_with_master.inc
152+
[On Slave]
153+
include/show_binlog_events.inc
154+
Log_name Pos Event_type Server_id End_log_pos Info
155+
slave-bin.000001 # Query # # use `test`; CREATE USER IF NOT EXISTS 'u1'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*6DD89A65903AC3BCC4873BA43D17EFFB912C67EE'
156+
slave-bin.000001 # Query # # use `test`; CREATE USER IF NOT EXISTS 'u1'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*AD3E6D897B165BF1FA7D3583FA1FF6AF31FA3C4B'
157+
slave-bin.000001 # Query # # use `test`; ALTER USER IF EXISTS 'u1'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*52BA180A884483D54A3CEB45FB50D4E5B8071399'
158+
slave-bin.000001 # Query # # use `test`; ALTER USER IF EXISTS 'u2_not_exists'@'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*53ED7183CBBC6D9995663DD96EFFA60E2CE2C96E'
159+
slave-bin.000001 # Query # # use `test`; DROP USER u1@localhost
160+
# Search warnings in the server log
43161
include/rpl_end.inc
44162

45163
End of 5.7 tests!

mysql-test/suite/binlog/t/binlog_user_if_exists.test

+112-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
--source include/not_embedded.inc
22
# Save the initial number of concurrent sessions
33
--source include/count_sessions.inc
4+
call mtr.add_suppression('Corresponding entry in binary log used default authentication.*');
5+
46
--source include/master-slave.inc
57
--connection master
6-
78
SHOW GLOBAL VARIABLES LIKE 'log_builtin_as_identified_by_password';
89

910
--echo #
1011
--echo # WL#8540: Support IF [NOT] EXISTS clause in CREATE/DROP USER
1112
--echo #
12-
1313
CREATE USER u1@localhost;
1414
CREATE USER IF NOT EXISTS u1@localhost, u2@localhost;
1515
ALTER USER IF EXISTS u1@localhost ACCOUNT LOCK;
@@ -19,18 +19,126 @@ DROP USER IF EXISTS u2@localhost;
1919
--echo #
2020
--echo # Bug #21807286: "CREATE USER IF NOT EXISTS" REPORTS AN ERROR
2121
--echo #
22-
23-
2422
CREATE USER IF NOT EXISTS b21807286@localhost IDENTIFIED BY 'haha';
2523
CREATE USER IF NOT EXISTS b21807286@localhost IDENTIFIED BY 'haha2';
2624
ALTER USER IF EXISTS b21807286@localhost IDENTIFIED BY 'haha3';
2725
ALTER USER IF EXISTS b21807286_not_exists@localhost IDENTIFIED BY 'haha4';
2826
DROP USER b21807286@localhost;
2927

28+
--source include/sync_slave_sql_with_master.inc
29+
--echo [On Slave]
30+
--source include/show_binlog_events.inc
31+
32+
--echo #
33+
--echo # Bug #25813089: "CREATE USER IF NOT EXISTS SHOULD ALWAYS
34+
--echo # BE WRITTEN TO THE BINLOGS"
35+
--echo #
36+
37+
# Scenario 1: Create/Alter user executed on a single user
38+
39+
--echo # ------
40+
--echo "Scenario 1: CREATE/ALTER USER IF[NOT]EXISTS FOR A SINGLE USER"
41+
--echo # ------
42+
--connection master
43+
# Save master position
44+
--let $saved_master_pos= query_get_value('SHOW MASTER STATUS', Position, 1)
45+
--let $binlog_start= $saved_master_pos
46+
47+
CREATE USER u1@localhost IDENTIFIED BY 'pass1';
48+
CREATE USER IF NOT EXISTS u1@localhost IDENTIFIED BY 'pass2';
49+
ALTER USER u1@localhost IDENTIFIED BY 'pass3';
50+
ALTER USER IF EXISTS u1@localhost IDENTIFIED BY 'pass4';
51+
ALTER USER IF EXISTS u1_not_exists@localhost IDENTIFIED BY 'pass5';
52+
DROP USER u1@localhost;
53+
54+
--echo [On Master]
55+
--source include/show_binlog_events.inc
3056

3157
--source include/sync_slave_sql_with_master.inc
3258
--echo [On Slave]
3359
--source include/show_binlog_events.inc
60+
61+
--echo "Creating a user only on slave"
62+
CREATE USER IF NOT EXISTS slave_user@localhost IDENTIFIED BY 'slave_pass';
63+
64+
# Scenario 2: Create/Alter user executed on multiple users
65+
# irrespective of whether they are present on master or not
66+
67+
--echo # ------
68+
--echo "Scenario 2: CREATE/ALTER USER IF[NOT]EXISTS FOR MULTIPLE USERS"
69+
--echo # ------
70+
--connection master
71+
# Save master position
72+
--let $saved_master_pos= query_get_value('SHOW MASTER STATUS', Position, 1)
73+
--let $binlog_start= $saved_master_pos
74+
CREATE USER IF NOT EXISTS u1@localhost IDENTIFIED BY 'pass1',
75+
u2@localhost IDENTIFIED BY 'pass2';
76+
77+
CREATE USER IF NOT EXISTS u1@localhost IDENTIFIED BY 'pass1',
78+
u2@localhost IDENTIFIED BY 'pass2',
79+
u3@localhost IDENTIFIED BY 'pass3';
80+
81+
ALTER USER IF EXISTS u1@localhost IDENTIFIED BY 'pass4',
82+
u2@localhost IDENTIFIED BY 'pass5',
83+
u3@localhost IDENTIFIED BY 'pass6',
84+
u4_not_exists@localhost IDENTIFIED BY 'pass7',
85+
slave_user@localhost IDENTIFIED BY 'pass8';
86+
DROP USER IF EXISTS u1@localhost, u2@localhost, u3@localhost, slave_user@localhost;
87+
88+
--echo [On Master]
89+
--source include/show_binlog_events.inc
90+
91+
--source include/sync_slave_sql_with_master.inc
92+
--echo [On Slave]
93+
--source include/show_binlog_events.inc
94+
95+
# Scenario 3: Make sure that the default authentication plugin is not used
96+
# when the plugin is specified explicitly while creating or altering users.
97+
98+
--echo # ------
99+
--echo "Scenario 3: CREATE/ALTER USER IF[NOT]EXISTS WITH"
100+
--echo "AUTHENTICATION PLUGIN PROVIDED EXPLICITLY"
101+
--echo # ------
102+
--connection master
103+
--let $rpl_server_number= 1
104+
--let $rpl_server_parameters= --default_authentication_plugin=sha256_password
105+
--source include/rpl_restart_server.inc
106+
107+
--disable_warnings
108+
--source include/rpl_reset.inc
109+
--enable_warnings
110+
111+
# Save master position
112+
--let $saved_master_pos= query_get_value('SHOW MASTER STATUS', Position, 1)
113+
--let $binlog_start= $saved_master_pos
114+
115+
SHOW VARIABLES LIKE 'default_authentication_plugin';
116+
CREATE USER IF NOT EXISTS u1@localhost IDENTIFIED WITH mysql_native_password by 'pass_native';
117+
CREATE USER IF NOT EXISTS u1@localhost IDENTIFIED WITH mysql_native_password by 'pass_native2';
118+
ALTER USER IF EXISTS u1@localhost IDENTIFIED WITH mysql_native_password BY 'pass_native3';
119+
ALTER USER IF EXISTS u2_not_exists@localhost IDENTIFIED WITH mysql_native_password BY 'pass_native4';
120+
SELECT user,authentication_string FROM mysql.user WHERE user='u1';
121+
DROP USER u1@localhost;
122+
123+
--echo [On Master]
124+
--source include/show_binlog_events.inc
125+
126+
--source include/sync_slave_sql_with_master.inc
127+
--echo [On Slave]
128+
--source include/show_binlog_events.inc
129+
130+
# Search for the warnings in the server log
131+
let server_log= $MYSQLTEST_VARDIR/log/mysqld.1.err;
132+
let SEARCH_FILE= $server_log;
133+
--echo # Search warnings in the server log
134+
135+
--let SEARCH_PATTERN= Following users were specified in CREATE USER IF NOT EXISTS
136+
--source include/search_pattern_in_file.inc
137+
138+
--let SEARCH_PATTERN= Following users were specified in ALTER USER IF EXISTS
139+
--source include/search_pattern_in_file.inc
140+
141+
#Clean up
34142
--source include/rpl_end.inc
35143

36144
--echo

mysql-test/suite/rpl/r/rpl_user_if_exists.result

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Note #### Storing MySQL user name or password information in the master info rep
88
#
99
[On Master]
1010
# No users exist:
11+
call mtr.add_suppression('Corresponding entry in binary log used default authentication.*');
1112
DROP USER IF EXISTS wl8540@nohost1, wl8540@nohost2;
1213
Warnings:
1314
Note 3162 User 'wl8540'@'nohost1' does not exist.
@@ -96,4 +97,5 @@ Warnings:
9697
Note 3162 User 'slave_user2'@'localhost' does not exist.
9798
FLUSH PRIVILEGES;
9899
include/sync_slave_sql_with_master.inc
100+
# Search warnings in the server log
99101
include/rpl_end.inc

mysql-test/suite/rpl/t/rpl_user_if_exists.test

+15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Created: 2015-07-01 Lalit Choudhary
22
# WL#8540
33
# Testing IF [NOT] EXISTS clause in CREATE/DROP/ALTER USER with Replication.
4+
45
--source include/master-slave.inc
56
--connection master
67
--echo [On Master]
@@ -10,6 +11,12 @@
1011
--echo [On Master]
1112
--echo # No users exist:
1213

14+
# For already existing users in case of CREATE USER IF NOT EXISTS
15+
# and for non-existing users in case of ALTER USER IF EXISTS,
16+
# the warnings will be generated if default authentication plugin
17+
# is used while writing the entries to binlog.
18+
call mtr.add_suppression('Corresponding entry in binary log used default authentication.*');
19+
1320
DROP USER IF EXISTS wl8540@nohost1, wl8540@nohost2;
1421
SELECT COUNT(*) FROM mysql.user WHERE user = 'wl8540';
1522
ALTER USER IF EXISTS wl8540@nohost1, wl8540@nohost2 ACCOUNT LOCK;
@@ -80,5 +87,13 @@ FLUSH PRIVILEGES;
8087

8188
--source include/sync_slave_sql_with_master.inc
8289

90+
# Search for the warnings in the server log
91+
let server_log= $MYSQLTEST_VARDIR/log/mysqld.1.err;
92+
let SEARCH_FILE= $server_log;
93+
--echo # Search warnings in the server log
94+
95+
--let SEARCH_PATTERN= Following users were specified in CREATE USER IF NOT EXISTS
96+
--source include/search_pattern_in_file.inc
97+
8398
--source include/rpl_end.inc
8499
# End:

0 commit comments

Comments
 (0)