Migrating a site from one server to the next is usually a pain. It’s not that it’s a difficult task in itself. It’s just that you’ll come across one silly error and end up spending days on it.
When importing a MySQL database (Usually via PhpMyAdmin), you might come across the following error:
Unknown collation: ‘utf8mb4_unicode_520_ci’
There were a few StackOverflow answers that were decently helpful. The most reliable solution I found was this underrated one by VUUB.
He essentially tells you that there are three parts in your SQL file that you have to find and replace.
The only problem is that this takes a while if you have multiple SQL files. So let’s automate it!
I decided to create a Python file to make this process easier. You can either download the script here or copy-and-paste it from below.
There is only one change you have to make. Edit the file_base_names
array and add the basenames of all of your files. (For example, if you have the file mysite.sql
, the basename would be mysite
) You could add as many basenames as you want.
Copy the script into the directory where your sql files are and then run it using the command python3 fixsqlutf.py
.
You will now have new SQL files titled “{your base name}-fixed.sql”.
Hope this helps!
Leave a comment