When importing a MySQL/MariaDB database, especially between different versions of MySQL, MariaDB or different server environments, you might encounter an error like this:
ERROR 1273 (HY000) at line [line_number]: Unknown collation: ‘utf8mb4_0900_ai_ci’
This error typically occurs because the collation used in the exported SQL file is not recognized by the MySQL/MariaDB server you’re trying to import into. The collation utf8mb4_0900_ai_ci
was introduced in MySQL 8.0, and if you’re trying to import this database into an older version of MySQL (like 5.7 or earlier), it won’t recognize this collation, leading to the error.

Understanding the Collation Error
Collation refers to the set of rules used to compare and sort textual data in a database. Each collation belongs to a character set, which defines the characters that can be stored. The utf8mb4_0900_ai_ci
collation is a case-insensitive collation for the utf8mb4
character set, and it was introduced in MySQL 8.0.
When your MySQL server does not support this collation, the import process fails, and you get the error mentioned above. To fix this, you need to replace the unsupported collation with one that is recognized by your MySQL version.
Step-by-Step Guide to Fix the ‘Unknown Collation’ Error
Here’s how you can resolve the issue:
Step 1: Locate the SQL File
First, identify the SQL file you’re trying to import. This file will typically be the one you’ve exported from another MySQL server, and it contains all the necessary commands to recreate your database, including table structures, data, and collation settings.
Step 2: Open the SQL File in a Text Editor
Next, open the .sql
file in a text editor. You can use any text or code editor, such as:
- Notepad++
- Sublime Text
- Visual Studio Code
- Atom
Step 3: Find the Problematic Collation
Use the search functionality in your text editor to locate all instances of utf8mb4_0900_ai_ci
. In most text editors, you can do this by pressing Ctrl + F
(Windows/Linux) or Cmd + F
(Mac) and typing in utf8mb4_0900_ai_ci
.
Step 4: Replace the Collation
Replace all instances of utf8mb4_0900_ai_ci
with utf8mb4_unicode_ci
. This collation is widely supported across various versions of MySQL and should work without issues.
Here’s how you can do it:
- In the search bar, type
utf8mb4_0900_ai_ci
. - In the replace bar, type
utf8mb4_unicode_ci
. - Click on ‘Replace All’ to make the changes throughout the entire file.
Step 5: Save the Edited SQL File
After replacing the collation, save the file. Ensure the file remains in its original .sql
format to ensure the integrity of the database structure and data.
Step 6: Reattempt the Import
Now, try to import the modified .sql
file into your MySQL server again. You can do this through a MySQL client like phpMyAdmin, MySQL Workbench, or through the command line:
Using Command Line:
mysql -u username -p database_name < path_to_your_sql_file.sql
Or use cPanel or your hosting control panel database restore feature.

If the collation was the issue, the import should now proceed without errors.
Conclusion
Database migrations and imports between different MySQL versions can sometimes lead to unexpected issues, like the one involving the utf8mb4_0900_ai_ci
collation. This problem arises due to differences in collation support between MySQL versions. By manually editing the SQL file to replace the unsupported collation with a compatible one (utf8mb4_unicode_ci
), you can successfully resolve the error and proceed with your import.
Additional Tips
- Always back up your database before making changes. If something goes wrong, you can always restore the original data.
- Test the import in a staging environment before applying it to a production server.
- Consider upgrading MySQL to a version that supports the newer collations if possible. This will help you avoid similar issues in the future.
By following these steps, you can efficiently resolve the Unknown collation: 'utf8mb4_0900_ai_ci'
error and ensure your database import process runs smoothly.