Change MySQL Table Collation

Submitted by: 
Visitors have accessed this post 4868 times.

In my previous post, I explained on how to Convert MyISAM to InnoDB. This time I’ll show you on how to change the collation of MySQL database tables. BTW, collation controls the way string values are sorted.
This code is useful if the table collation varied from each other. Example one table has utf8_general_ci collation, while the other has utf8_unicode_ci. It’s a best practice if there is uniformity with the table collation to avoid conflict in your data.
Some of the codes in this article are taken from the internet. I just revised some of it so you will benefit from this code.
Be sure to change the following code attached here to fit your needs.

  1. $username = "root";
  2. $password = "";
  3. $db = "database";
  4. $host = "localhost";
  6. $target_charset = "utf8";
  7. $target_collate = "utf8_general_ci";

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.


1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.


I'm looking for this code for several weeks...thank u.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.