utf8mb4 database upgrader CLI
Upgrade your WordPress database to `utf8mb4` via WP-CLI
by Jason Cosper · github.com/boogah/utf8mb4-cli-upgrader · website
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/boogah/utf8mb4-cli-upgrader/archive/refs/heads/main.ziputf8mb4 database upgrader for WP-CLI
Force upgrade your WordPress database to utf8mb4 via WP-CLI.
Description
This WordPress plugin is designed to upgrade your WordPress database to utf8mb4 via WP-CLI. The plugin will go through each table in your database and upgrade its collation to utf8mb4_unicode_ci.
Why would you do this? Maybe your WordPress install missed running this conversion when WordPress 4.2 first shipped. If it did, you may be affecting your site's performance — so upgrading your database is a good idea. You'd be surprised how often this comes up even on sites running WordPress 6.0 or later. The core function this plugin relies on has existed since WordPress 4.2, but a minimum of 5.0 is required — if your site is older than that, you have bigger problems.
Installation
- Upload the plugin files to the
/wp-content/plugins/utf8mb4-cli-upgraderdirectory, or install the plugin through the WordPress plugins screen directly. - The plugin can be run via WP-CLI with the following command:
wp upgrade_utf8mb4.
Requirements
- WordPress 5.0 or higher
- PHP 7.4 or higher
Usage
To run the utf8mb4 upgrade on your WordPress database, use the WP-CLI command:
wp upgrade_utf8mb4
The output will look like this:
Table wp_commentmeta current collation: utf8_general_ci
Table wp_commentmeta converted. New collation: utf8mb4_unicode_ci
Table wp_comments current collation: utf8_general_ci
Table wp_comments converted. New collation: utf8mb4_unicode_ci
Table wp_links current collation: utf8_general_ci
Table wp_links converted. New collation: utf8mb4_unicode_ci
Table wp_options current collation: utf8_general_ci
Table wp_options converted. New collation: utf8mb4_unicode_ci
Table wp_postmeta current collation: utf8_general_ci
Table wp_postmeta converted. New collation: utf8mb4_unicode_ci
Table wp_posts current collation: utf8_general_ci
Table wp_posts converted. New collation: utf8mb4_unicode_ci
Table wp_term_relationships current collation: utf8_general_ci
Table wp_term_relationships converted. New collation: utf8mb4_unicode_ci
Table wp_term_taxonomy current collation: utf8_general_ci
Table wp_term_taxonomy converted. New collation: utf8mb4_unicode_ci
Table wp_termmeta current collation: utf8_general_ci
Table wp_termmeta converted. New collation: utf8mb4_unicode_ci
Table wp_terms current collation: utf8_general_ci
Table wp_terms converted. New collation: utf8mb4_unicode_ci
Table wp_usermeta current collation: utf8_general_ci
Table wp_usermeta converted. New collation: utf8mb4_unicode_ci
Table wp_users current collation: utf8_general_ci
Table wp_users converted. New collation: utf8mb4_unicode_ci
Notes
Please run a backup of your database before running this plugin's CLI command on your site. It's as straightforward as running wp db export before running the wp upgrade_utf8mb4 command.
Once this plugin has been run, you do not need to keep it active or installed on your site. Please get rid of the plugin by deleting it once you're done using it!
Changelog
1.1.0
- Bumped minimum requirements to WordPress 5.0 and PHP 7.4
- Fixed SQL injection vulnerability by using
$wpdb->prepare() - Improved code to meet WordPress coding standards
- Simplified table loop using
$wpdb->get_col() - Switched to
WP_CLI::log()andWP_CLI::success()for better CLI output
1.0.0
- Initial Release