4
2

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.

[WordPress][MySQL] WordPress の全テーブルのエンジンをすべて innodb に変更する

Posted at

小ネタ。
wp-cli を使って WordPress の全エンジンを InnoDB に変える方法。
ちまちま ALTER TABLE 発行するのも疲れるので。
こんな感じのシェルスクリプト作って実行すればいいんでないかな。

modify-engine.sh
#!/bin/bash
WP_PATH=${1:-/var/www/html}
TABLES=$(wp --path=${WP_PATH} db tables --all-tables)
for TABLE in ${TABLES}; do
    echo "** ${TABLE} **"
    wp --path=${WP_PATH} db query "ALTER TABLE ${TABLE} ENGINE=innodb, ALGORITHM=COPY;"
done

現在のテーブルのエンジンが何かを調べたい場合も、wp-cli でできるよ。

$ wp db query "SELECT table_schema, table_name, engine FROM information_schema.tables WHERE table_schema='$(wp eval 'echo DB_NAME;')';"
+--------------+-----------------------------+--------+
| table_schema | table_name                  | engine |
+--------------+-----------------------------+--------+
| wordpress    | wp_commentmeta              | InnoDB |
| wordpress    | wp_comments                 | InnoDB |
| wordpress    | wp_links                    | InnoDB |
| wordpress    | wp_options                  | InnoDB |
| wordpress    | wp_postmeta                 | InnoDB |
| wordpress    | wp_posts                    | InnoDB |
| wordpress    | wp_term_relationships       | InnoDB |
| wordpress    | wp_term_taxonomy            | InnoDB |
| wordpress    | wp_termmeta                 | InnoDB |
| wordpress    | wp_terms                    | InnoDB |
| wordpress    | wp_usermeta                 | InnoDB |
| wordpress    | wp_users                    | InnoDB |
+--------------+-----------------------------+--------+
4
2
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
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?