MySQL ユーザー作成・権限付与
rootでログイン
mysql -uroot -ppassword
新たにユーザーを作成
create user {new_user} identified by '{password}';
権限付与
権限付与の構文
grant 権限内容 on 権限対象DB to ユーザー identified by 'パスワード';
権限内容
- all privileges:GRANT(権限の付与)以外のすべての権限
- alter:テーブル変更
- create:テーブル作成
- drop:テーブル削除
- index:インデックス作成、削除
- select:select文
- insert:insert文
- update:update文
- delete:delete文
権限対象
# グローバル権限 *.* # データベース my_database.* # テーブル (my_databaseのmy_tableテーブルが対象) my_database.my_table
例
grant alter, create, drop, index on *.* to new_user identified by 'password';
権限設定の反映
flush privileges;
付与した権限の確認
show grants for master_user;