您的位置:首页 > 博客中心 > 数据库 >

浅析mysql主从复制中复制用户的权限管理

时间:2022-03-13 23:58

    在用复制账号对mysql salve管理过程中,使用哪些权限合适?首先看一下mysql官方提供的权限表:

服务器管理

    怎样找到复制账户的最小权限?

    首先使用root账号登陆,收回复制账号repl_user的所有权限:

mysql> select user();

+----------------+

| user()         |

+----------------+

| root@localhost |

+----------------+

1 row in set (0.00 sec)

mysql> revoke all on *.* from repl_user;

Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

    其次使用repl_user登陆:

mysql> show slave status\G;

ERROR 1227 (42000): Access denied; you need (at least one of) the SUPER,REPLICATION CLIENT privilege(s) for this operation

    错误提示,至少需要SUPER和REPLICATION CLIENT这两个权限之一。

    (1)赋予REPLICATION CLIENT权限给repl_user

mysql> grant REPLICATION CLIENT ON *.* TO repl_user;

Query OK, 0 rows affected (0.00 sec)

mysql> show slave status\G;

*************************** 1. row ***************************

               Slave_IO_State: Connecting to master

                  Master_Host: 192.168.6.100

                  Master_User: repl_user

                  Master_Port: 3306

                Connect_Retry: 60

                            ......

    show slave status\G;状态查看正常,但是管理slave提示如下:

mysql> stop slave;

ERROR 1045 (28000): Access denied for user ‘repl_user‘@‘%‘ (using password: YES)

    (2)赋予REPLICATION SLAVE权限给repl_user:

mysql> grant REPLICATION SLAVE ON *.* TO repl_user;

Query OK, 0 rows affected (0.00 sec)

mysql> stop slave;

ERROR 1045 (28000): Access denied for user ‘repl_user‘@‘%‘ (using password: YES)

mysql> SELECT Repl_slave_priv,Repl_client_priv,super_priv FROM mysql.USER WHERE USER=‘repl_user‘;

+-----------------+------------------+------------+

| Repl_slave_priv | Repl_client_priv | super_priv |

+-----------------+------------------+------------+

| Y               | Y                | N          |

+-----------------+------------------+------------+

1 row in set (0.00 sec)

    (3)赋予SUPER权限给repl_user:

mysql> grant SUPER ON *.* TO repl_user;

Query OK, 0 rows affected (0.00 sec)

mysql> stop slave;

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> start slave;

Query OK, 0 rows affected, 1 warning (0.00 sec)

    (4)赋予RELOAD权限给repl_user

    在没有RELOAD权限时提示如下错误:

mysql> reset slave;

ERROR 1227 (42000): Access denied; you need (at least one of) the RELOAD privilege(s) for this operation

mysql> grant reload on *.* to repl_user;

Query OK, 0 rows affected (0.00 sec)

mysql> reset slave;

Query OK, 0 rows affected (0.00 sec)

    最后,总结如下:

    REPLICATION CLIENT(客户端)、REPLICATION SLAVE(服务端)、SUPER(管理)和RELOAD四个权限最好在创建用户时就赋予,以免造成不必要的麻烦,当然,要是主主配置,最好给予ALL权限。

    上述只是在工作中的一点思考,希望看到这篇博文的博友给予指正。

    

热门排行

今日推荐

热门手游