Skip to content

Instantly share code, notes, and snippets.

@TCattd
Created June 9, 2016 15:40
Show Gist options
  • Save TCattd/257962d42523199ee1f2eb06e3400ea3 to your computer and use it in GitHub Desktop.
Save TCattd/257962d42523199ee1f2eb06e3400ea3 to your computer and use it in GitHub Desktop.
<?php
/*
* Upload it to the same directory as wp-config.php and run it vía web
*
* Original idea from http://www.sanjaybhowmick.com/how-to-convert-mysql-collation-from-utf8mb4-to-utf8/
*/
include_once 'wp-config.php';
$dbname = DB_NAME;
mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysql_query("ALTER DATABASE `$dbname` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci");
$result = mysql_query("SHOW TABLES FROM `$dbname`");
while($row = mysql_fetch_row($result)) {
$query = "ALTER TABLE {$dbname}.`{$row[0]}` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci";
mysql_query($query);
$query = "ALTER TABLE {$dbname}.`{$row[0]}` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci";
mysql_query($query);
}
echo 'All the tables have been converted successfully to utf8_general_ci';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment