ユーザー作成
mysql -u root -- rootでログイン
create user {user名}@localhost identified by {パスワード} -- ユーザー作成
作成したユーザーの確認
use mysql -- DB'mysql'に移動
select * from user -- ユーザーを確認
権限追加
構文
grant {権限内容} on {権限対象} to {ユーザー名}@{ホスト名} identified by {パスワード}
-- test_dbのselect権限をtestユーザーに追加
grant select on test_db.* to test@localhost identified by {パスワード};
-- test_dbの全権限をtestユーザーに追加
grant all on test_db.* to test@localhost identified by {パスワード};
-- 全DBの全権限をtestユーザーに追加
grant all on *.* to test@localhost identified by {パスワード};
追加した権限の確認
- dbテーブル
host名、db名、user名、追加されている権限一覧を確認
select * from db
- 追加したdbへのアクセス
-- 作成したユーザーでログイン
mysql -u test -p
-- db確認。 権限を追加したDBを確認できる。
show databases
権限削除
構文
revoke {権限内容} on {権限対象} to {ユーザー名}@{ホスト名} identified by {パスワード}
-- testユーザーからfile権限を削除
revoke file on *.* from test@localhost;