mysqlの権限参照

– どのユーザーがいるか知りたい
SELECT user, host, password FROM mysql.user
mysql> select user,host from mysql.user;
+——+———————–+
| user | host |
+——+———————–+
| user | % |
| root | 127.0.0.1 |
| root | ::1 |
| | localhost |
| root | localhost |
| saru | localhost |
| | localhost.localdomain |
| root | localhost.localdomain |
+——+———————–+
8 rows in set (0.21 sec)

-ユーザー権限
SHOW GRANTS FOR root@`localhost`

mysql> show grants for root@localhost;
+———————————————————————+
| Grants for root@localhost |
+———————————————————————+
| GRANT ALL PRIVILEGES ON *.* TO ‘root’@’localhost’ WITH GRANT OPTION |
| GRANT PROXY ON ”@” TO ‘root’@’localhost’ WITH GRANT OPTION |
+———————————————————————+
2 rows in set (0.06 sec)

– 管理用ユーザー
GRANT ALL ON *.* TO adminuser@`%` IDENTIFIED BY ‘password’ WITH GRANT OPTION;

– IP制限
GRANT ALL ON *.* TO adminuser@’172.16.0.0/255.255.255.0′ IDENTIFIED BY ‘password’ WITH GRANT OPTION;

– 全てのデータベースにアクセス
GRANT ALL ON *.* TO testuser@’%’ IDENTIFIED By ‘password’;

– 特定のデータベースにアクセス
GRANT ALL ON testdatabase.* TO testuser@’%’ IDENTIFIED BY ‘password’;

ref: create user with GRANT Privileges in Terminal