Recently I faced a tough situation with one of my WordPress site at the time of exporting MySQL database. My development MySQL server supports utf8mb4 collation but the production MySQL server does not support that. So, I had to convert all the tables of the MySQL database from utf8mb4 to utf8. The actual task was conversion from utf8mb4_unicode_ci to utf8_general_ci
I tried to convert manually several times but it did not work. My question was what is the difference between utf8mb4 and utf8?
utf8mb4 (as well as standard UTF-8) can directly store any character specified by Unicode; the former is fixed size at 4 bytes per character whereas the latter is between 1 and 4 bytes per character.
utf8 can only store the first 65,536 codepoints, which will cover CJVK (Chinese, Japanese, Vietnam, Korean), and use 1 to 3 bytes per character.
So, the real process will be ALTER the database as well as each database table to change the CHARACTER SET. Using a PHP script I made the conversion and it worked perfectly. This is the PHP script which will convert your MySQL database collation from utf8mb4_unicode_ci to utf8_general_ci instantly.
The code worked, this is really help me out, thanks a lot.
Sencillamente genial… Thanks!
SOS script. Thanks it Really saved.
Amazing, life-saving, thanks a lot !!!!!!!!!!!!!!!!
nice catch on the change in the config file, I had missed that !
Nice Job mate…. Thanks alot
Hey Sanjay, that script worked perfectly! Thank you a lot, it saved me a ton of time!
Thx for the script … saved me a lot of time today 🙂
Thank You so Much!! I have searched everywhere for a solution. This is the only one that works!! Thank Goodness!!
Thanks, it worked fine but “term_relationships”. How to convert this table please?
Hello!!
How long does it take to convert the database? I got the success message but when I tried to upload the db to the new server still getting the error. My database is very big, like 200 M
Generally you can not upload 200M file into any PHPMyAdmin. You have to edit your php.ini file and set the maximum values for
memory_limit
post_max_size
upload_max_filesize
and then restart your webserver.
¡¡¡¡GENIUS!!!! Thanks a lot.
I tried this script on my localhost installation and got a success message. But the table names in the database still showed ‘utf8mb4_unicode_520_ci’ and when I tried to migrate the website with Duplicator plugin I got database errors ‘unknown collation’, The migration failed. What else do I need to do for a successful migration. I do not know any programming but can handle some code editing.
Hope you can help.
Thanks.
Email me your sql file at me@sanjaybhowmick.com and I shall convert it for you.
Thanks for the offer. I have sent you the file. Still, it would be nice if you can please post the steps for doing it. I will be needing it more than once and others might too.
i AM ALSO FACING THE SAME PROBLEM , AND I HAVE ALSO USED THE THE dbconversion.php code . BUT NOTHING HAPPENED.
wow it works!..thanks