mysql> SHOW GRANTS FOR 'not_leet'@'localhost';
+------------------------------------------------------------------------------------------------------------------------------------+
| Grants for not_leet@localhost |
+------------------------------------------------------------------------------------------------------------------------------------+
| GRANT SELECT, REPLICATION CLIENT ON *.* TO 'not_leet'@'localhost' IDENTIFIED BY PASSWORD '*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' |
+------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
更改“ not _ leet”和“ localhost”以匹配要添加的新用户以及密码,将导致创建新用户的可重用 GRANT语句。
ALL PRIVILEGES- This would allow a MySQL user all access to a designated database (or if no database is selected, across the system)
CREATE- allows them to create new tables or databases
DROP- allows them to them to delete tables or databases
DELETE- allows them to delete rows from tables
INSERT- allows them to insert rows into tables
SELECT- allows them to use the Select command to read through databases
UPDATE- allow them to update table rows
GRANT OPTION- allows them to grant or remove other users' privileges
要向特定用户提供权限,可以使用以下框架:
GRANT [type of permission] ON [database name].[table name] TO ‘[username]’@'localhost’;
CREATE USER 'readonly_user'@'localhost' IDENTIFIED BY 'some_strong_password';
GRANT SELECT, SHOW VIEW ON *.* TO 'readonly_user'@'localhost';
flush privileges;
# 1. connect as an admin on database / cluster
mysql -u root -h mydb.123456789012.us-east-1.rds.amazonaws.com
# 2. create user protected with strong password with global access ('%') or local access ('localhost')
mysql> CREATE USER 'ro_user'@'%' IDENTIFIED BY 'abcd1234%^&#';
# 3. grant SELECT privileges for relevant user
mysql> GRANT SELECT ON *.* TO 'ro_user'@'%' WITH GRANT OPTION;
# 4. reload grant tables on database
mysql> FLUSH PRIVILEGES;
# 5. verify grant are placed as expected
mysql> show grants for 'ro_user'@'%';
// output:
// +------------------------------------------------------+
// | Grants for ro_user@% |
// +------------------------------------------------------+
// | GRANT SELECT ON *.* TO 'ro_user'@'%' WITH GRANT OPTION |
// +------------------------------------------------------+
// 1 row in set (0.00 sec)
mysql> exit