3
3

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 2015-06-08

色んな所から抜粋

dbサーバへログイン
$ mysql -u [user_name] -p

rootパスワード設定

mysql> update mysql.user set password=password('root用の任意パスワード') where user = 'root';
mysql> flush privileges;

パスワードリセットローカル
set password=‘’;

パスワードリセットホスト
grant all privileges on [db_name].* to root@"192.168.0.1" identified by '' with grant option;
grant all privileges on [db_name].* to root@"192.168.0.%" identified by '' with grant option;

dbの作成
mysql> create database [db_name];

ユーザ作成
mysql> create user [user_name]

ユーザの確認
mysql> select host,user from mysql.user;

権限の付与(ユーザ作成含む)
mysql> grant all on [db_name].* to [user_name]@対象IP identified by '[password]';

色々
管理者権限付き
grant all privileges on *.* to root@localhost identified by '[password]' with grant option;
grant all privileges on *.* to root@"%" identified by '[password]' with grant option;
一般ユーザ
grant select,insert,update,delete on [db_name].* to [user_name]@"192.168.%" identified by '[PASSWORD]';

dbの選択
mysql> use [db_name];

dbのデータベース一覧
mysql> show databases;

dbのテーブル一覧
mysql> show tables;

dbのステータス
mysql> show status;

mysqldの文字コード
mysql> show variables like 'character_%';

dbの文字コード
mysql> show create database [db_name];


**バックアップ・リストア**

dbのダンプファイルを生成(rootでもよい)
$ mysqldump -u [user_name] -p [password] [db_name] > [dumpfile]

リストア先のdbを作成
mysql> create database [db_name] default character set utf8;

リストア先のdbユーザと権限を設定
mysql> grant all privileges on [db_name].* to [user_name]@localhost identified by '[password]';

dbのリストア
$ mysql -u [user_name] -p [password] [db_name] < [dumpfile]


**全てのデータベースをバックアップ** `$ mysqldump -u root -x --all-databases > dumpfile` **特定のデータベースのみバックアップ** `$ mysqldump -u root > dump.sql` **複数のデータベースをバックアップする場合** `$ mysqldump -u root --databases db1 db2 db3`
3
3
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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?