252
268

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 5 years have passed since last update.

MySQL の権限のコマンドまとめ。

Posted at

まずどのユーザーがいるか知りたい。

SELECT user,host,password FROM mysql.user;

###個々のユーザーの権限はなにか知りたい。

SHOW GRANTS FOR root@'localhost';

###いわゆる何でもできる管理者用ユーザ

GRANT ALL ON *.* TO adminuser@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;

※MySQLにはGRANT権限というものがあります。GRANT権限とは、他のユーザに対して権限を付与することができる権限のことです。当然のことながらGRANT権限は通常管理者用ユーザにか付与しません。

###IP制限

GRANT ALL ON *.* TO adminuser@'172.16.0.0/255.255.255.0' IDENTIFIED BY 'password' WITH GRANT OPTION;

###全てのデータベースにアクセスできる一般ユーザ(WITH GRANT OPTIONがないのに注目)

GRANT ALL ON *.* TO testuser@'%' IDENTIFIED BY 'password';

###特定のデータベースにアクセスできる一般ユーザ

GRANT ALL ON testdatabase.* TO testuser@'%' IDENTIFIED BY 'password';

init_connect
らへんは、

###SELECT,INSERT,UPDATE,DELETEしかできない一般ユーザ

GRANT SELECT,INSERT,UPDATE,DELETE ON testdatabase.* TO testuser@'%' IDENTIFIED BY 'password';

###手動で権限テーブルをリロードする

FLUSH PRIVILEGES;

参考:init_connectコマンドが失敗したらしい。

252
268
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
252
268

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?