2
1

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

[MySQL] ユーザー追加、削除、権限付与する方法

Posted at

[MySQL] ユーザー追加、削除、権限付与する方法

接続

$ mysql -u root -p

ユーザー確認

mysql> use mysql;

mysql> select host,user from user;

1.png

ユーザー追加

mysql> create user 'ユーザー'@'localhost(又は%)' identified by 'パスワード';

①%は外部から接続を可能よする設定です。

ユーザー削除

mysql> drop user 'ユーザー'@'localhost';

ユーザー権限付与

mysql> grant all privileges on *.* to 'ユーザー'@'localhost';

mysql> grant all privileges on DB名.* to 'ユーザー'@'localhost';

mysql> grant all privileges on DB名.テーブル名 to 'ユーザー'@'localhost';

mysql> grant select on DB名.テーブル名 to 'ユーザー'@'localhost';

mysql> grant update(カラム2, カラム1) on DB名.テーブル名 to 'ユーザー'@'localhost';

①all privieges はすべての権限を付与する意味です。

②*.*はすべてデータベースそして、すべてのテーブルを指定する意味です。

③@後ろに特定IPを設定できます。

ユーザー権限削除

mysql> revoke all on DB名.* from 'ユーザー'@'localhost';

ユーザー権限確認

mysql> show grants for 'ユーザー'@'localhost';
2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?