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.

MySQL のテーブルを InnoDB に一括変換する方法

Last updated at Posted at 2019-09-24

MySQL のテーブルを一括で InnoDB に変換する方法です。

MySQL データベース一覧を取得し、InnoDB に一括変換する SQL をコマンドで作成し、実行する方法を解説します。

手順

1. バックアップ

データベースをバックアップします。

2. 実行用 SQL を生成

MySQL のテーブル一覧をリストし、SQL ファイルとして一括変更できる準備をします。

(mysql -h {DB Host} -u {DB User} -p {DB Name} -e "show tables" --batch --skip-column-names | xargs -I{} echo 'alter table `'{}'` ENGINE=InnoDB;') > alter_innodb_$(date +%Y%m%d%H%M%S).sql

文字列を以下のように書き換えて実行します。

文字列 書き換え先
{DB Host} DB ホストアドレス
{DB User} DB ユーザー名
{DB Name} DB 名

alters_20190924XXXXXX.sql といったファイル名で SQL ファイルが生成されます。

3. SQL ファイルを確認 & 編集

SQL ファイルを確認し、MyISAM テーブルのままでいたいテーブルを削除します。

例えば concrete5.6.4.0 では、

  • FileVersions
  • PageSearchIndex
  • PageStatistics

この3つのテーブルは MyISAM のままで良いので、
SQL ファイルを編集してこの3行を探し削除します。

4. SQL を実行

生成された SQL を実行。

mysql -h {DB Host} -u {DB User} -p {DB NAME} < alter_innodb_XXXXXXXXXXXX.sql

5. 確認

Squel Pro などの MySQL クライアントソフトを使って確認

以上

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?