0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【MySQL】権限を確認/付与するコマンド

Posted at

使用する機会があったのでメモです。

ユーザーを確認

mysql> select user(), current_user();
+----------------+----------------+
| user()         | current_user() |
+----------------+----------------+
| root@localhost | root@localhost |
+----------------+----------------+
1 row in set (0.00 sec)

※SELECT USER()は接続に使用されているユーザー名とホスト名を返し、SELECT CURRENT_USER()は現在のセッションのユーザー名とホスト名を返す。

権限の確認

mysql> SHOW GRANTS FOR 'root'@'localhost';
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost                                                                                                                                                             |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| GRANT SELECT, RELOAD, SHUTDOWN, PROCESS, SHOW DATABASES, SUPER, LOCK TABLES, REPLICATION SLAVE, REPLICATION CLIENT, CREATE USER, EVENT ON *.* TO `root`@`localhost` WITH GRANT OPTION |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

権限を与える方法

データベース全体への権限を付与

GRANT 権限種類 ON データベース名.* TO 'ユーザー名'@'ホスト名';

特定のテーブルへの権限を付与

GRANT 権限種類 ON データベース名.テーブル名 TO 'ユーザー名'@'ホスト名';

全てのデータベースへの権限を付与

GRANT 権限種類 ON *.* TO 'ユーザー名'@'ホスト名';

例:'root'@'localhost'に全てのデータベースへの全ての権限を付与する場合

mysql> GRANT ALL ON *.* TO 'root'@'localhost';
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?