LoginSignup
0
1

More than 5 years have passed since last update.

MySQLチートシート

Last updated at Posted at 2019-03-05

mysqldumpで特定のdbをgzipでバックアップ&リストア

バックアップ

mysqldump -u ${user} -p --single-transaction ${db_name} --ignore-table=mysql.event | gzip > ${db_name}.dmp.gz.`date +%Y%m%d`

リストア

zcat ${db_name}.dmp.gz.`date +%Y%m%d` | mysql -u ${user} -p ${db_name}

全テーブルの大雑把なレコード数を一覧表示する

各テーブルのレコード数を確認したい時に使用する。例えばレプリケーションやリストアの確認の時など。

ただし、information_schemaはわりと大雑把なので、完全に一致しないこともあるので注意。
その場合は select count する。
公式ドキュメントにも以下のように記載がある。

For InnoDB tables, the row count is only a rough estimate used in SQL
optimization. (This is also true if the InnoDB table is partitioned.)

全DBの全テーブル

mysql> select table_name, table_rows from information_schema.TABLES;

特定のDBの全テーブル

mysql> select table_name, table_rows from information_schema.TABLES where table_schema = '${db_name}';
0
1
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
0
1