TIPS

WordPressのテーブルプレフィックスを変更する方法

wp-config.phpを開き、「$table_prefix = ‘wp_’;」を
任意のプレフィックス「$table_prefix = ‘newprefix_’;」に変更します。

次に、データベースのプレフィックスの変更します。
以下は「wp_」を「newprefix_」にリネームするSQLコマンドです。phpmyadminでGUIで変更してもOK。

RENAME table wp_commentmeta TO newprefix_commentmeta;
RENAME table wp_comments TO newprefix_comments;
RENAME table wp_links TO newprefix_links;
RENAME table wp_options TO newprefix_options;
RENAME table wp_postmeta TO newprefix_postmeta;
RENAME table wp_posts TO newprefix_posts;
RENAME table wp_terms TO newprefix_terms;
RENAME table wp_termmeta TO newprefix_termmeta;
RENAME table wp_term_relationships TO newprefix_term_relationships;
RENAME table wp_term_taxonomy TO newprefix_term_taxonomy;
RENAME table wp_usermeta TO newprefix_usermeta;
RENAME table wp_users TO newprefix_users;

newprefix_optionsテーブルを開き、次のレコードを探して「wp_」から「newprefix_」に変更します。

  • option_nameが「wp_user_roles」 → newprefix_user_roles
  • option_nameが「wp_capabilities」 → newprefix_capabilities

newprefix_usermetaテーブル内のレコードも同様に変更します。

  • meta_keyが「wp_capabilities」 → newprefix_capabilities
  • meta_keyが「wp_user_level」 → newprefix_user_level

注意: 変更前にデータベースのバックアップを作成することを強くおすすめします。
プレフィックスを変更した場合、関連するプラグインやカスタムテーマに影響を与える可能性があります。特に、直接テーブル名を指定しているカスタムコードやクエリがある場合は、変更したプレフィックスに合わせて修正する必要があります。