Description:
In MySQL Community Server 5.7.17 and 5.7.16,
Use the grant statement to authorize two users at the same time, a user exists, a user does not exist,the grant statement returns 1133 error(ERROR 1133 (42000): Can't find any matching row in the user table),
But which will be written to a LOST_EVENTS event to binlog.
And user already exists will be successfully authorized.
binlog information:
/*!*/;
# at 731
#170330 13:26:03 server id 1 end_log_pos 825 CRC32 0x41285f86
# Incident: LOST_EVENTS
RELOAD DATABASE; # Shall generate syntax error
# at 825
#170330 13:26:03 server id 1 end_log_pos 869 CRC32 0x70d00a82 Rotate to binlog.000002 pos: 4
SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/;
DELIMITER ;
# End of log file
And binlog has been rotate.
How to repeat:
Vsesion: MySQL Community Server 5.7.17
Platform:linux x64
Repeat step:
mysql> show master status;
+---------------+----------+--------------+------------------+------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+------------------------------------------+
| binlog.000001 | 486 | | | be7815ee-0897-11e7-a197-c81f66de7923:1-2 |
+---------------+----------+--------------+------------------+------------------------------------------+
1 row in set (0.00 sec)
mysql> select user,host from mysql.user;
+-----------+-----------+
| user | host |
+-----------+-----------+
| mysql.sys | localhost |
| root | localhost |
+-----------+-----------+
2 rows in set (0.00 sec)
mysql> CREATE USER 'test'@'%' IDENTIFIED by 'test';
Query OK, 0 rows affected (0.00 sec)
mysql> select user,host from mysql.user;
+-----------+-----------+
| user | host |
+-----------+-----------+
| test | % |
| mysql.sys | localhost |
| root | localhost |
+-----------+-----------+
3 rows in set (0.00 sec)
mysql> show grants for 'test'@'%';
+----------------------------------+
| Grants for test@% |
+----------------------------------+
| GRANT USAGE ON *.* TO 'test'@'%' |
+----------------------------------+
1 row in set (0.00 sec)
mysql> show master status;
+---------------+----------+--------------+------------------+------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+------------------------------------------+
| binlog.000001 | 731 | | | be7815ee-0897-11e7-a197-c81f66de7923:1-3 |
+---------------+----------+--------------+------------------+------------------------------------------+
1 row in set (0.00 sec)
mysql> GRANT USAGE ON *.* TO ''@'','test'@'%' WITH GRANT OPTION;
ERROR 1133 (42000): Can't find any matching row in the user table
mysql> show master status;
+---------------+----------+--------------+------------------+------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+------------------------------------------+
| binlog.000002 | 194 | | | be7815ee-0897-11e7-a197-c81f66de7923:1-3 |
+---------------+----------+--------------+------------------+------------------------------------------+
1 row in set (0.00 sec)
mysql> show grants for 'test'@'%';
+----------------------------------------------------+
| Grants for test@% |
+----------------------------------------------------+
| GRANT USAGE ON *.* TO 'test'@'%' WITH GRANT OPTION |
+----------------------------------------------------+
1 row in set (0.00 sec)
mysql> show binlog events in "binlog.000001";
+---------------+-----+----------------+-----------+-------------+---------------------------------------------------------------------------------------------------------------+
| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |
+---------------+-----+----------------+-----------+-------------+---------------------------------------------------------------------------------------------------------------+
| binlog.000001 | 4 | Format_desc | 1 | 123 | Server ver: 5.7.17-log, Binlog ver: 4 |
| binlog.000001 | 123 | Previous_gtids | 1 | 154 | |
| binlog.000001 | 154 | Gtid | 1 | 219 | SET @@SESSION.GTID_NEXT= 'be7815ee-0897-11e7-a197-c81f66de7923:1' |
| binlog.000001 | 219 | Query | 1 | 320 | drop user if exists 'test'@'%' |
| binlog.000001 | 320 | Gtid | 1 | 385 | SET @@SESSION.GTID_NEXT= 'be7815ee-0897-11e7-a197-c81f66de7923:2' |
| binlog.000001 | 385 | Query | 1 | 486 | drop user if exists 'test'@'%' |
| binlog.000001 | 486 | Gtid | 1 | 551 | SET @@SESSION.GTID_NEXT= 'be7815ee-0897-11e7-a197-c81f66de7923:3' |
| binlog.000001 | 551 | Query | 1 | 731 | CREATE USER 'test'@'%' IDENTIFIED WITH 'mysql_native_password' AS '*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29' |
| binlog.000001 | 731 | Incident | 1 | 825 | #1 (LOST_EVENTS) |
| binlog.000001 | 825 | Rotate | 1 | 869 | binlog.000002;pos=4 |
+---------------+-----+----------------+-----------+-------------+---------------------------------------------------------------------------------------------------------------+
10 rows in set (0.00 sec)
mysql> show binlog events in "binlog.000002";
+---------------+-----+----------------+-----------+-------------+------------------------------------------+
| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |
+---------------+-----+----------------+-----------+-------------+------------------------------------------+
| binlog.000002 | 4 | Format_desc | 1 | 123 | Server ver: 5.7.17-log, Binlog ver: 4 |
| binlog.000002 | 123 | Previous_gtids | 1 | 194 | be7815ee-0897-11e7-a197-c81f66de7923:1-3 |
+---------------+-----+----------------+-----------+-------------+------------------------------------------+
2 rows in set (0.00 sec)