When attempting to change a MySQL table's collation to utf8_general_cs, many developers encounter the error:
ERROR 1273 (HY000): Unknown collation: 'utf8_general_cs'
This occurs because utf8_general_cs is not a built-in collation in MySQL. The confusion often comes from the fact that MySQL has case-sensitive collations, but they follow different naming conventions.
For UTF8 character sets, MySQL provides these case-sensitive alternatives:
utf8_bin
utf8_unicode_ci (case-insensitive)
utf8_general_ci (case-insensitive)
To verify available collations in your MySQL installation, run:
SHOW COLLATION WHERE Charset = 'utf8';
For case-sensitive comparisons, use utf8_bin which performs binary comparisons:
ALTER TABLE table_name
CONVERT TO CHARACTER SET utf8
COLLATE utf8_bin;
If you specifically need the general collation with case sensitivity, you might need to:
-- First change to binary
ALTER TABLE table_name
CONVERT TO CHARACTER SET utf8
COLLATE utf8_bin;
-- Then create a custom collation if needed
-- (This requires MySQL 8.0+ and server configuration)
If you need case-sensitive behavior for specific queries without changing the table collation:
SELECT * FROM table_name
WHERE column_name COLLATE utf8_bin = 'SearchTerm';
In newer MySQL versions, utf8mb4 is preferred over utf8:
ALTER TABLE table_name
CONVERT TO CHARACTER SET utf8mb4
COLLATE utf8mb4_bin;
The utf8mb4 character set supports the full Unicode character set including emojis and is generally recommended for modern applications.
If you encounter further problems:
- Check your MySQL version:
SELECT VERSION();
- Verify character sets:
SHOW CHARACTER SET;
- Check table current collation:
SHOW CREATE TABLE table_name;
When attempting to change a MySQL table's collation to utf8_general_cs, you might encounter the error "Unknown collation: 'utf8_general_cs'". This occurs because this specific case-sensitive collation isn't available by default in modern MySQL installations. The utf8_general_ci (case-insensitive) variant is commonly available, but the case-sensitive version was deprecated and removed in newer MySQL versions.
First, verify which collations are actually available in your MySQL installation:
SHOW COLLATION WHERE Charset = 'utf8';
You'll typically see collations like:
- utf8_general_ci
- utf8_bin
- utf8_unicode_ci
If you specifically need case-sensitive collation, consider these alternatives:
Option 1: Use utf8_bin
The binary collation provides case-sensitivity:
ALTER TABLE table_name
CONVERT TO CHARACTER SET utf8
COLLATE utf8_bin;
Option 2: Upgrade to utf8mb4
For newer MySQL versions (5.5.3+), use utf8mb4 with its binary collation:
ALTER TABLE table_name
CONVERT TO CHARACTER SET utf8mb4
COLLATE utf8mb4_bin;
If migrating from an older system that used utf8_general_cs:
- Test all string comparisons in your application
- Verify sorting behavior matches expectations
- Check any application code relying on case-sensitive matching
For MySQL 8.0+, you can potentially create a custom collation if absolutely needed:
CREATE COLLATION my_cs_collation (
LOCALE = 'en_US.utf8',
PROVIDER = 'icu',
DETERMINISTIC = TRUE
);
However, this requires ICU library support and thorough testing.
Changing collation affects:
- Existing indexes (they will be rebuilt)
- Query performance (binary collations are generally faster)
- Storage requirements (may increase slightly)