在用复制账号对mysql salve管理过程中,使用哪些权限合适?首先看一下mysql官方提供的权限表:
权限 | 列 | 上下文 |
CREATE | Create_priv | 数据库、表或索引 |
DROP | Drop_priv | 数据库或表 |
GRANT OPTION | Grant_priv | 数据库、表或保存的程序 |
REFERENCES | References_priv | 数据库或表 |
ALTER | Alter_priv | 表 |
DELETE | Delete_priv | 表 |
INDEX | Index_priv | 表 |
INSERT | Insert_priv | 表 |
SELECT | Select_priv | 表 |
UPDATE | Update_priv | 表 |
CREATE VIEW | Create_view_priv | 视图 |
SHOW VIEW | Show_view_priv | 视图 |
ALTER ROUTINE | Alter_routine_priv | 保存的程序 |
CREATE ROUTINE | Create_routine_priv | 保存的程序 |
EXECUTE | Execute_priv | 保存的程序 |
FILE | File_priv | 服务器主机上的文件访问 |
CREATE TEMPORARY TABLES | Create_tmp_table_priv | 服务器管理 |
LOCK TABLES | Lock_tables_priv | 服务器管理 |
CREATE USER | Create_user_priv | 服务器管理 |
PROCESS | Process_priv | 服务器管理 |
RELOAD | Reload_priv | 服务器管理 |
REPLICATION CLIENT | Repl_client_priv | 服务器管理 |
REPLICATION SLAVE | Repl_slave_priv | 服务器管理 |
SHOW DATABASES | Show_db_priv | 服务器管理 |
SHUTDOWN | Shutdown_priv | 服务器管理 |
SUPER | Super_priv | 服务器管理 |
怎样找到复制账户的最小权限?
首先使用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权限。
上述只是在工作中的一点思考,希望看到这篇博文的博友给予指正。
原文地址:http://gfsunny.blog.51cto.com/990565/1554627