Home >Database >Mysql Tutorial >How Can I Recover Damaged UTF-8 Encoding in MySQL?

How Can I Recover Damaged UTF-8 Encoding in MySQL?

Linda Hamilton
Linda HamiltonOriginal
2024-12-14 16:21:11319browse

How Can I Recover Damaged UTF-8 Encoding in MySQL?

Recovering Damaged UTF-8 Encoding

When encountering corrupted UTF-8 encodings, such as "î," troubleshooting can be challenging. To address this issue, consider the following solution:

For MySQL databases with damaged UTF-8 characters (e.g., accented characters), execute the following steps:

  1. Create a Dump File:
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
  1. Import the Dump File:
mysql -h DB_HOST -u DB_USER -p DB_PASSWORD \
    --default-character-set=utf8 DB_NAME < DB_NAME-dump.sql

Note: These steps will convert the character set to latin1 during the dump process and back to utf8 during the import, which rectifies the encoding issues.

Source:

http://blog.hno3.org/2010/04/22/fixing-double-encoded-utf-8-data-in-mysql/

The above is the detailed content of How Can I Recover Damaged UTF-8 Encoding in MySQL?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn