如何在 MySQL 中授予数据库复制权限?
要授予复制权限,请使用 GRANT REPLICATION SLAVE ON。
首先列出 MySQL.user 表中的所有用户名和主机 -
mysql> select user,host from mysql.user;
这将产生以下输出 -
+------------------+-----------+ | 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)
让我们实现以上语法,向 MySQL 中的一个数据库授予复制权限 -
mysql> GRANT REPLICATION SLAVE ON *.* TO 'Mike'@'localhost'; Query OK, 0 rows affected (0.20 sec)
让我们检查一下授予是否成功 -
mysql> SHOW GRANTS FOR 'Mike'@'localhost';
这将产生以下输出 -
+------------------------------------------------------+ | Grants for Mike@localhost | +------------------------------------------------------+ | GRANT REPLICATION SLAVE ON *.* TO `Mike`@`localhost` | +------------------------------------------------------+ 1 row in set (0.04 sec)
广告