The error message “Error 1273: Unknown collation ‘utf8mb4_0900_ai_ci'” typically occurs in MySQL databases when trying to use a collation that is not recognized by the server. This collation, introduced in MySQL 8.0, is based on the Unicode Collation Algorithm 9.0.0 and supports a wide range of Unicode characters. If your MySQL server version is older than 8.0, it won’t recognize this collation, leading to the error. This issue is relevant because it affects database compatibility and data integrity during migrations or imports between different MySQL versions.
The error 1273 Unknown Collation utf8mb4_0900_ai_ci
occurs when MySQL encounters a collation it doesn’t recognize. This typically happens if the MySQL server version is older than 8.0.1, which introduced the utf8mb4_0900_ai_ci
collation.
utf8mb4
is a character set that supports a wide range of characters, including emojis.utf8mb4_0900_ai_ci
is a collation where:
utf8mb4
is the character set.0900
indicates the version.ai
stands for accent-insensitive.ci
stands for case-insensitive.To resolve this error, you can replace utf8mb4_0900_ai_ci
with a collation supported by your MySQL version, such as utf8mb4_unicode_ci
.
Here are the common causes of the error 1273: Unknown collation 'utf8mb4_0900_ai_ci'
:
Version Incompatibility:
utf8mb4_0900_ai_ci
was introduced in MySQL 8.0. If you’re using an older version of MySQL, it won’t recognize this collation.Mismatched Collation:
utf8mb4_0900_ai_ci
, this error can occur. This often happens during database imports or migrations from sources using different collations.Backup and Restore Issues:
utf8mb4_0900_ai_ci
, the error can occur if the target server does not support this collation. Editing the backup file to replace utf8mb4_0900_ai_ci
with a supported collation like utf8mb4_general_ci
can resolve this.Configuration Settings:
utf8mb4_0900_ai_ci
, causing compatibility issues during database operations.Sure, here’s a detailed, step-by-step guide to resolve the “Error 1273: Unknown collation ‘utf8mb4_0900_ai_ci'” issue:
Locate the SQL File
Open the SQL File in a Text Editor
.sql
file.Find the Problematic Collation
utf8mb4_0900_ai_ci
.Replace the Collation
utf8mb4_0900_ai_ci
with utf8mb4_unicode_ci
or utf8mb4_general_ci
. These collations are widely supported across various MySQL versions.CHARSET=utf8mb4
with CHARSET=utf8
if necessary.Example:
ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
Replace with:
ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
Save the Edited SQL File
.sql
format.Reattempt the Import
.sql
file into your MySQL server again. You can use a MySQL client like phpMyAdmin, MySQL Workbench, or the command line.Using Command Line:
mysql -u username -p database_name < path_to_your_sql_file.sql
sed
Command for Linux UsersIf you are using a Linux system, you can use the sed
command to replace text in files directly:
sed -i 's/utf8mb4_0900_ai_ci/utf8_general_ci/g' backup.sql
sed -i 's/CHARSET=utf8mb4/CHARSET=utf8/g' backup.sql
After these changes, the database should be successfully restored.
: TecAdmin
: SatisfyHost
: Meetanshi
To prevent encountering the “Error 1273: Unknown collation ‘utf8mb4_0900_ai_ci'” in future database migrations or imports, follow these tips and best practices:
utf8mb4_0900_ai_ci
with utf8mb4_unicode_ci
or utf8mb4_general_ci
in your SQL files and database configurations.utf8mb4_0900_ai_ci
.utf8mb4_unicode_ci
..sql
dump files in a text editor and replace any instances of utf8mb4_0900_ai_ci
with a compatible collation.Implementing these practices will help ensure smoother database migrations and imports.
To resolve the “Error 1273: Unknown collation ‘utf8mb4_0900_ai_ci'” when importing a MySQL database, you need to replace the unsupported collation with a compatible one. The error occurs due to the use of the ‘utf8mb4_0900_ai_ci’ collation in your SQL file or database configuration, which is not supported by older versions of MySQL.
sed -i 's/utf8mb4_0900_ai_ci/utf8_general_ci/g' backup.sql sed -i 's/CHARSET=utf8mb4/CHARSET=utf8/g' backup.sql
After making these changes, the database should be successfully restored.
Implementing these practices will help ensure smoother database migrations and imports.