6
6

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 コマンド

Last updated at Posted at 2014-05-21

ユーザーの作成


 > GRANT ALL PRIVILEGES ON *.* TO user名@host名 IDENTIFIED BY 'password' WITH GRANT OPTION;

権限付与


グローバルレベル:
GRANT 権限 ON *.* TO user;

データベースレベル:
GRANT 権限 ON db_name.* TO user;

テーブルレベル:
GRANT 権限 ON db_name.table_name TO user;

カラムレベル:
GRANT 権限 (カラム1, カラム2, ...) ON db_name.table_name TO user;

ALL PRIVILEGES 全ての権限を与える
WITH GRANT OPTION 権限の書き換えを許可する

権限を書き換えたら、


> flush privileges;

権限確認


show grants for 'user'@'localhost';

現在接続しているユーザー
show grants;
show grants for current_user();

ユーザーの確認


> SELECT host,user FROM mysql.user;

ユーザーの権限を確認、


> SHOW GRANTS FOR user名;

パスワードの変更


>  SET PASSWORD FOR user名@"host名"=password('変更後のパスワード');

ユーザーの削除


> DELETE FROM mysql.user WHERE user='user名';

まとめて確認


mysql> select Host, User, Password from mysql.user;

参考 http://sasuke.main.jp/useri.html#2

バックアップ、リストア

データベース指定バックアップ
# mysqldump -u root -p db_name > dumpfile.sql

データベース指定リストア
# mysql -u user -p  db_name < dumpfile.sql

※注意点:データベース指定なのか全体なのか

memo

show grants for 'hogehoge'@'localhost';
set password for 'hogehoge'@'localhost' = password('**');
grant all on (データベース名とか).
to 'hogehoge'@'localhost';
show databases;
USE (データベースの名前);
show tables;
SELECT User, Host FROM mysql.user;
drop user 'user'@'localhost';

6
6
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
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?