fbpx

Convert WordPress Tables to utf8mb4

WordPress version 4.2 changed up the default database table collation. Swapping to utf8mb4 provides support for a wider range of characters, including emojis. If the contents of your content editor are deleted when saving with an emoji in it, this is probably your issue.

If you upgraded to WordPress 4.2 while running MySQL version 5.5.2 or lower, this wouldn’t have happened automatically like it should have. MySQL 5.5.2 and lower don’t support the new collation.

The following code can be added to your functions or a custom plugin to force-run the upgrade on all database tables once you’re running an updated version of MySQL.

// Notice admin_init - will only run in backend
add_action('admin_init', function() {
	require_once(ABSPATH.'/wp-admin/includes/upgrade.php');
	global $wpdb;
	$mytables=$wpdb->get_results("SHOW TABLES");
	foreach ($mytables as $mytable)
	{
	    foreach ($mytable as $t) 
	    {       
	        maybe_convert_table_to_utf8mb4( $t );
	    }
	}
	
});

Index Resizing

This update also brought changes to the size of the indexes. That database upgrade should have happened regardless of your MySQL version, so you shouldn’t need to worry about updates to that.


Are You a Do-It-Yourself WordPress-er?

If you aren't ready to invest in Sterner Stuff, I've got something for you! Check out my new (and free) WordPress for Small Business Owners email course!

Leave a reply

Your email address will not be published. Required fields are marked *