error-Unknown-collation-utf8mb4_0900_ai_ci

Fix MySQL Error 1273: Unknown Collation 'utf8mb4_0900_ai_ci' – Using PowerShell to Patch .SQL Files

  • Profile picture of Mcs
  • by Mcs June 30, 2025

If you're working with MySQL databases across different versions, you've likely run into this frustrating error:

ERROR 1273 (HY000): Unknown collation: 'utf8mb4_0900_ai_ci'

This typically happens when importing a .sql dump from MySQL 8.0+ into an older MySQL version like 5.7 or 5.6. The culprit? The newer collation utf8mb4_0900_ai_ci, which isn't supported in older versions.

Why This Happens

MySQL 8.0 introduced new collations such as utf8mb4_0900_ai_ci. When you try to import a dump using this collation into an older version, MySQL throws error 1273 because it doesn't recognize it.

Instead of manually editing potentially thousands of lines in your .sql file, use PowerShell to automate the fix.

Quick Fix Using PowerShell

Here’s the command you’ll use:

(Get-Content "filename.sql") -replace 'utf8mb4_0900_ai_ci', 'utf8mb4_general_ci' | Set-Content "new-filename.sql"

What This Does:

  • Get-Content reads your SQL dump.
  • -replace changes every instance of the incompatible collation.
  • Set-Content writes the updated content to a new file.

Example:

(Get-Content "mydb-dump.sql") -replace 'utf8mb4_0900_ai_ci', 'utf8mb4_general_ci' | Set-Content "mydb-dump-fixed.sql"

Now import the fixed file:

mysql -u root -p mydatabase < mydb-dump-fixed.sql

Conclusion

This PowerShell one-liner is a lifesaver when migrating databases between different MySQL versions. It prevents you from wasting time manually editing large files and helps ensure smooth imports without collation errors.

Comments

Add new comment

Restricted HTML

  • Allowed HTML tags: <br> <p> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <cite> <dl> <dt> <dd> <a hreflang href> <blockquote cite> <ul type> <ol type start> <strong> <em> <code> <li>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.