[mysql] DB作成、ユーザー発行、権限付与

Tech


よく忘れるのでメモ。

CREATE DATABASE '';

CREATE USER 'root'@'%' IDENTIFIED BY 'password';

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';

こんな危ない設定はローカル以外では絶対にやらない事。

SELECT user, HOST FROM mysql.user;

+------------------+-----------+
| user             | host      |
+------------------+-----------+
| root             | %         |
| healthchecker    | localhost |
| mysql.infoschema | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
| root             | localhost |
+------------------+-----------+

ついでに権限確認も。

mysql> SHOW GRANTS FOR 'example'@'%';

+------------------------------------------------------+
| Grants for exmaple@%                                 |
+------------------------------------------------------+
| GRANT USAGE ON *.* TO `example`@`%`                  |
| GRANT ALL PRIVILEGES ON `example`.* TO `example`@`%` |
+------------------------------------------------------+