How to change all MySQL database table collation

Solution

After change the collation of a database, only the new tables will be created with the new collation. To change all the database collation, you can use the php script as below as it can change all the�collation for all the existing table.�

<?php
$db = mysql_connect('localhost','database_user','Password');
if(!$db) echo "Cannot connect to the database - incorrect details";
mysql_select_db('database_name'); $result=mysql_query('show tables');
while($tables = mysql_fetch_array($result)) {
foreach ($tables as $key => $value) {mysql_query("ALTER TABLE $value COLLATE�Collation");
}}
echo "The collation of your database has been successfully changed!";
?>

Note:
database_user : Database Username
Password: Database user password
database_name: Database Name
Collation : new collation

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

SQL (Structured Query Language)

Solution The Structured Query Language (SQL) comprises one of the fundamental building blocks of...

Do you guys support MySQL InnoDB Engine on your shared web hosting package?

InnoDB has had a history of being a unstable storage engine and InnoDB tables are very prone to...

Do you guys have a limitation on the database size on your shared web hosting package?

We will honestly answer you yes.The limit of our database is 300MB which is around 50,000-200,000...