LoginSignup
0
0

More than 1 year has passed since last update.

MySQLのコマンドラインでユーザー設定

Posted at

最初に

MySQLのコマンドラインで入力をキャンセルする方法

mysql> \c
mysql> ^C

\cを入力するか、Ctrl+Cでキャンセルできます。

作成済みのユーザーを確認する

select user, host from mysql.user;

現在接続しているユーザーを確認する

select user(), current_user();

ユーザーを作成する

パスワードなしのユーザーを作る

CREATE USER user;

パスワードありのユーザーを作る

CREATE USER user IDENTIFIED BY 'password';

ユーザー名・パスワード・ホスト名の設定されたユーザーを作る

  • ユーザー名 :user
  • ホスト名 : localhost
  • パスワード : password
create user `user`@`localhost` IDENTIFIED BY 'password';

ユーザーの権限を確認する

show grants for user@localhost;
--show grants for ユーザー名@ホスト名
mysql> show grants for user@localhost;
+------------------------------------------+
| Grants for user@localhost                |
+------------------------------------------+
| GRANT USAGE ON *.* TO `user`@`localhost` |
+------------------------------------------+
1 row in set (0.00 sec)

USAGE という権限は「何も権限がない」という権限です。

ユーザーにDB操作権限を与える

  • 対象 :user@localhost
grant create on *.* to user@localhost;
mysql> show grants for user@localhost;
+-------------------------------------------+
| Grants for user@localhost                 |
+-------------------------------------------+
| GRANT CREATE ON *.* TO `user`@`localhost` |
+-------------------------------------------+
1 row in set (0.00 sec)

CREATE になりました。

特定のDBの権限を与える

grant create on sampleDB.* to user@localhost;
-- grant create on データベース名.* to ユーザ名@localhost;

もっと詳しく権限を設定できます。
ユーザーに権限を設定する(GRANT文)

ユーザーを消す

drop user user;
--drop user ユーザー名;

参考HP

https://www.dbonline.jp/mysql/user/index1.html
https://www.dbonline.jp/mysql/user/index4.html
https://qiita.com/ysti/items/b4a84691c357167c89c2
https://www.dbonline.jp/mysql/user/index6.html

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