0
0

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.

MySQL8.0でMySQL5.7のデータベース構造を比較する

Posted at

コマンド

テーブル構造をダンプする

mysqldumpコマンドを使ってダンプします。

mysqldump -d -uroot -h127.0.0.1 -P3306  -p DB_NAME  --skip-create-options  --skip-column-statistics > dump_a.sql

MacのMySQLWorkbench8を使ったやり方

/Applications/MySQLWorkbench.app/Contents/MacOS/mysqldump -d -uroot -h127.0.0.1 -P3306  -p DB_NAME  --skip-create-options --skip-column-statistics > dump_a.sql

| 項目 | 説明 |
| :--: |:--: | :--: |
| -d | テーブル構造だけダンプするオプション |
| -u | ユーザ名 |
| -h | DBホスト名|
| -P | DBポート番号 |
| -p | DBパスワード |
| DB_NAME | ここにデータベース名(スキーマ名)を入れる |
| --skip-create-options | AUTO INCREMENTの値などのテーブルのオプションのを出力しない ※1 |
| --skip-column-statistics | MySQL8 から過去のバージョンのDumpを行うときに必要これがないとエラーになる※2 |
| dump_a.sql | ダンプ先ファイル名 お好みで変えてください |

テーブル構造を比較する

普通にdiffコマンドでいけます。

diff dump-a.sql dump-b.sql

バージョン情報

| software | version |
| :--: |:--: | :--: |
| mysql server | 5.7 | |
| mysqldump(MySQL Workbench for Mac) | mysqldump Ver 8.0.16 for macos10.14 on x86_64 (MySQL Community Server - GPL) | |

今回は、macにインストールしたMySQLWorkBenchに付属しているmysqldumpを利用していますが、
mysql clientが入っているマシンであれば、mysqldumpも入っているので、それを利用してもいいです。

参考

補足

※1 --skip-create-optionsをつけないときとつけた時の差分

> ) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4;
1861c1861
< ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

※2 --skip-column-statisticsをつけないときに発生するエラー

Unknown table 'COLUMN_STATISTICS' in information_schema (1109)
0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?