Home >Database >Mysql Tutorial >How Can I Fix Broken UTF-8 Encoding in My MySQL Database?
Fixing Broken UTF-8 Encoding: A Practical Solution
Background:
Users often encounter issues with broken UTF-8 encoding, characterized by characters like î instead of accented characters. This problem arises from inconsistencies in database collation, PHP settings, and storage methods.
Mapping Broken Characters to Correct UTF-8:
To resolve this issue, one effective approach involves a MySQL database dump and re-import process. This method allows for the conversion of broken characters to their correct UTF-8 representations.
Step-by-Step Fix:
1. Dump the MySQL database using the following command: mysqldump -h DB_HOST -u DB_USER -p DB_PASSWORD --opt --quote-names \ --skip-set-charset --default-character-set=latin1 DB_NAME > DB_NAME-dump.sql 2. Import the dumped data back into a new database with the correct UTF-8 settings: mysql -h DB_HOST -u DB_USER -p DB_PASSWORD \ --default-character-set=utf8 DB_NAME < DB_NAME-dump.sql
Source:
This solution is based on the technique described in:
http://blog.hno3.org/2010/04/22/fixing-double-encoded-utf-8-data-in-mysql/
Additional Notes:
The above is the detailed content of How Can I Fix Broken UTF-8 Encoding in My MySQL Database?. For more information, please follow other related articles on the PHP Chinese website!