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の権限まわりの備忘録

Last updated at Posted at 2023-01-13

・ユーザー作成

create user 'username' identified by 'password';

・ユーザー一覧の確認(usernameとhostnameのみ)

mysql> select user, host from mysql.user;
+------------------+-----------+
| user             | host      |
+------------------+-----------+
| root             | %         |
| scraper          | %         |
| mysql.infoschema | localhost |
+------------------+-----------+
3 rows in set (0.00 sec)

・ユーザー情報の確認(権限も確認可能、where句は検索条件、;の代わりに\Gで縦書きに変更)

mysql> select * from mysql.user where user='root'\G
*************************** 1. row ***************************
                    Host: %
                    User: root
             Select_priv: Y
             Insert_priv: Y
             Update_priv: Y
             Delete_priv: Y
             Create_priv: Y
               Drop_priv: Y
             Reload_priv: Y
           Shutdown_priv: Y
            Process_priv: Y
               File_priv: Y
              Grant_priv: N
         References_priv: Y
              Index_priv: Y
              Alter_priv: Y
(中略)

・ユーザー権限のみ確認

mysql> show grants for scraper\G
*************************** 1. row ***************************
Grants for scraper@%: GRANT USAGE ON *.* TO `scraper`@`%`
1 row in set (0.00 sec)

※「GRANT USAGE 」だと何も権限が付与されていない

※ 権限一覧の説明はこちら
https://www.javadrive.jp/mysql/user/index5.html
※ 公式ドキュメント
https://dev.mysql.com/doc/refman/8.0/ja/privileges-provided.html

・ユーザー権限の追加(Grant Option権限を付加)

mysql> update user set Grant_priv = "Y" where user = "root";
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

・grantテーブルの読み込み

mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)

(以下公式ドキュメントより引用)
https://dev.mysql.com/doc/refman/8.0/en/flush.html、

FLUSH PRIVILEGES

Re-reads the privileges from the grant tables in the mysql system schema. As part of this operation, the server reads the global_grants table containing dynamic privilege assignments and registers any unregistered privileges found there.

Reloading the grant tables is necessary to enable updates to MySQL privileges and users only if you make such changes directly to the grant tables; it is not needed for account management statements such as GRANT or REVOKE, which take effect immediately.

(翻訳)
mysql システム スキーマの付与テーブルから権限を再度読み取ります。 この操作の一環として、サーバーは、動的な権限の割り当てを含む global_grants テーブルを読み取り、そこで見つかった未登録の権限を登録します。 許可テーブルに直接変更を加えた場合にのみ、MySQL 権限とユーザーの更新を有効にするために、許可テーブルのリロードが必要です。 すぐに有効になる GRANT や REVOKE などのアカウント管理ステートメントには必要ありません。

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?