Importing a MySQL database but seeing strange symbols like ’
, é
, or error messages related to character sets or collations? You’re likely dealing with a character set mismatch — a common issue when databases are moved between servers or exported incorrectly.
In this guide, we’ll walk you through why it happens and how to fix character set errors when importing databases, especially within cPanel or phpMyAdmin.
❓ Common Errors You Might See
- Garbage characters in content (e.g., WordPress posts showing � or weird symbols)
- Errors like: sqlCopyEdit
ERROR 1115 (42000): Unknown character set: 'utf8mb4'
or pgsqlCopyEditERROR 1253 (42000): COLLATION 'utf8mb4_unicode_ci' is not valid for CHARACTER SET 'latin1'
🧠 Why This Happens
This usually occurs when:
- A database was exported using one character set (e.g.,
utf8mb4
) - But it’s being imported as another (e.g.,
latin1
) - Or your MySQL server version doesn’t support certain charsets/collations
✅ Step-by-Step: How to Fix Character Set Import Issues
🔹 Step 1: Check Character Set in SQL Dump
Open your .sql
file and look for lines like:
/*!40101 SET NAMES utf8mb4 */;
Or:
DEFAULT CHARSET=latin1
If it says latin1
, but your content contains UTF-8 (e.g., emojis or non-English text), you’ll likely run into issues.
🔹 Step 2: Fix Using Text Replacement (If Misdeclared)
If the data is actually utf8mb4
but the file says latin1
, fix it by replacing:
sed -i 's/CHARSET=latin1/CHARSET=utf8mb4/g' your_backup.sql
sed -i 's/SET NAMES latin1/SET NAMES utf8mb4/g' your_backup.sql
Alternatively, edit the .sql
file in a text editor like VS Code or Notepad++.
🔹 Step 3: Specify the Correct Charset on Import (via CLI)
When importing via the command line, explicitly set the correct character set:
mysql --default-character-set=utf8mb4 -u username -p database_name < your_backup.sql
✅ This ensures MySQL doesn’t assume the wrong encoding.
🔹 Step 4: Fix phpMyAdmin Upload Charset (Optional)
If using phpMyAdmin, before you import:
- Choose the correct collation (e.g.,
utf8mb4_general_ci
) in the import page. - Then upload the
.sql
file
💡 Bonus: How to Export Databases Correctly (Prevent Future Issues)
When exporting from mysqldump
, always define a character set:
mysqldump --default-character-set=utf8mb4 --skip-comments --set-gtid-purged=OFF --column-statistics=0 -u root -p database_name > clean_backup.sql
This keeps character set declarations consistent and import-safe.
🧪 Optional: Force Charset in WordPress wp-config.php
If you’re restoring a WordPress site and seeing strange characters:
define('DB_CHARSET', 'utf8mb4');
define('DB_COLLATE', '');
Add or confirm these in wp-config.php
🛑 Still Seeing Weird Symbols?
- The data may have already been stored incorrectly.
- In this case, a search & replace tool like WP-CLI’s
search-replace
can help. - Or restore the data again using the proper charset and collation from the start.
✅ Summary: Fixing Charset Import Errors
Problem | Solution |
---|---|
Unknown character set error | Replace with a known one (e.g., utf8mb4) |
Weird symbols after import | Force charset on import |
latin1 in dump but content is UTF-8 | Replace all latin1 with utf8mb4 before import |
Using phpMyAdmin | Choose correct charset in UI |
⚡ Need Help With Character Set Issues or Corrupted Imports?
👉 Servers9 offers professional database restoration and cleanup
We can recover content, fix charset mismatches, and safely import even damaged .sql
files.