How to grant replication privilege to a database in MySQL?


To grant replication privilege, use GRANT REPLICATION SLAVE ON.

First list all the user names along with host from MySQL.user table −

mysql> select user,host from mysql.user;

This will produce the following output −

+------------------+-----------+
| user             | host      |
+------------------+-----------+
| Bob              | %         |
| Charlie          | %         |
| Robert           | %         |
| User2            | %         |
| mysql.infoschema | %         |
| mysql.session    | %         |
| mysql.sys        | %         |
| root             | %         |
| @UserName@       | localhost |
| Adam             | localhost |
| Adam Smith       | localhost |
| Chris            | localhost |
| David            | localhost |
| James            | localhost |
| John             | localhost |
| John Doe         | localhost |
| Mike             | localhost |
| User1            | localhost |
| am               | localhost |
| hbstudent        | localhost |
| mysql.infoschema | localhost |
| mysql.session    | localhost |
+------------------+-----------+
22 rows in set (0.00 sec)

Let us implement the above syntax to grant replication privilege to a database in MySQL −

mysql> GRANT REPLICATION SLAVE ON *.* TO 'Mike'@'localhost';
Query OK, 0 rows affected (0.20 sec)

Let us check the grant is successful or not −

mysql> SHOW GRANTS FOR 'Mike'@'localhost';

This will produce the following output −

+------------------------------------------------------+
| Grants for Mike@localhost                            |
+------------------------------------------------------+
| GRANT REPLICATION SLAVE ON *.* TO `Mike`@`localhost` |
+------------------------------------------------------+
1 row in set (0.04 sec)
raja
Published on 23-Aug-2019 16:45:43
Advertisements