LoginSignup
5
6

More than 5 years have passed since last update.

MySQLで構築初期の時によく使うコマンド

Last updated at Posted at 2016-10-14

MySQLでよく使うコマンドなど(自分用メモです)

インストール後の初期設定

$ mysql_secure_installation

データベースと、そのデータベースの全権限を持つユーザを作成する

mysql> CREATE DATABASE hogedb DEFAULT CHARACTER SET utf8;
mysql> GRANT ALL ON hogedb.* TO 'hogeuser'@'localhost' IDENTIFIED BY 'hogepass';

データベースをコピーする

別名のデータベースを作成する。

mysql> CREATE DATABASE hogedb_new DEFAULT CHARACTER SET utf8;
mysql> GRANT ALL ON hogedb_new.* TO 'hogeuser'@'localhost';

コマンドラインで、ダンプデータを取得してそれを流す。

$ mysqldump -u hogeuser -phogepass hogedb > hogedb.dump.sql
$ mysql -u hogeuser -phogepass hogedb_new < hogedb.dump.sql

テーブルをコピーする

コピー元テーブルと同じ構造のテーブルを作成してから、データをインサートする

mysql> CREATE TABLE new_tables LIKE tables;
mysql> INSERT INTO new_tables SELECT * FROM tables;

不要なユーザを削除する

権限を削除してから、ユーザを削除する

mysql> REVOKE ALL PRIVILEGES ON *.* FROM 'hogehoge'@'localhost';
mysql> DROP USER 'hogehoge'@'localhost';
5
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
5
6