Knowledgebase
Webinova Online Customer Support > Webinova Help Desk > Knowledgebase

Search help:


How to change the collation for all tables in a MySQL database to UTF-8?

Solution

Changing the collation for all tables in a MySQL database can be time consuming depending on how many tables you have.

That’s why we recommend using the following PHP script for changing the collation for all tables at a time:

<?php
$db = mysql_connect(‘localhost’,’myuser_mydbuser‘,’mypassword‘);
if(!$db) echo "Cannot connect to the database – incorrect details";
mysql_select_db(‘myuser_mydbname’); $result=mysql_query(‘show tables’);
while($tables = mysql_fetch_array($result)) {
foreach ($tables as $key => $value) {
mysql_query("ALTER TABLE $value COLLATE utf8_general_ci");
}}
echo "The collation of your database has been successfully changed!";
?>

Make sure to substitute in the above script:

- myuser_mydbname with your database name;

- myuser_mydbuser with your mysql username;

- mypassword with your password for the mysql user;

- utf8-general_ci with your new collation if different;

 
Was this article helpful? yes / no
Article details
Article ID: 196
Category: cPanel MySQL Databases
Date added: 2012-12-07 13:07:10
Views: 34
Rating (Votes): Article rated 3.0/5.0 (6)

 
« Go back

 
Powered by Help Desk Software HESK - brought to you by Help Desk Software SysAid