Skip to content

Instantly share code, notes, and snippets.

@rutger1140
Created June 16, 2011 14:02
Show Gist options
  • Save rutger1140/1029277 to your computer and use it in GitHub Desktop.
Save rutger1140/1029277 to your computer and use it in GitHub Desktop.
Convert MySQL character set and collations to utf8_unicode_ci
<?php
/**
* Convert MySQL tables to utf8_unicode_ci
*/
// Prevent accidental execution
die("Please open and update this file before executing it :)");
// Your connection
mysql_connect("localhost","development","development");
mysql_select_db("your-database-name");
// Convert code
$res = mysql_query("SHOW TABLES");
while ($row = mysql_fetch_array($res)){
foreach ($row as $key => $table){
mysql_query("ALTER TABLE " . $table . " CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci");
echo $key . " =&gt; " . $table . " CONVERTED<br />";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment