Home > Database > phpMyAdmin > What should I do if the sql file exported by phpmyadmin is garbled?

What should I do if the sql file exported by phpmyadmin is garbled?

藏色散人
Release: 2020-04-01 09:24:56
Original
2668 people have browsed it

What should I do if the sql file exported by phpmyadmin is garbled?

What should I do if the sql file exported by phpmyadmin is garbled?

phpMyAdmin version is 2.9.1.1

Use phpMyAdmin to back up the database. After exporting it, when restoring it locally with sqlyog, The following error occurred:

Error occured at:2009-03-03 10:09:43
Line no.:11154
Error Code: 1062 - Duplicate entry '??????' for key 2
Copy after login

Open the sql file and take a look. The member user names under the membership table are garbled characters, all similar to ???, ????, because many programs now support Chinese users. name, and the username is unique. After the Chinese username becomes garbled, many identical usernames appear. When we import these garbled data, there is already a username like ?????? , so if the second one appears below, an error will be reported

If you have control over the system, you can use the following command to export the data, and there will be no garbled characters, and it will be normal during restoration

mysqldump -uroot -p --default-character-set=utf8 --set-charset --skip-opt dbname > newdbname.sql
Copy after login

But now I can only use phpMyAdmin to export. After testing for a long time, I found that if the Language of phpMyAdmin is "中文-chinese simplified-gb2312", the exported sql file is gb2312. Some tables have Chinese characters, and the Chinese characters are Garbled characters. When the Language of phpMyAdmin is "Chinese-chinese simplified (that is, utf8)", the character set of the exported sql file is utf8 (use Notepad to view the format, which shows that it is UTF-8 without BOM format encoding). Chinese can be displayed normally

Therefore, in order to avoid garbled Chinese in the exported file, you can select Chinese-chinese simplified from the Language drop-down menu, and then select export. The Chinese in the downloaded sql file will be It can be displayed normally.

Use the following command to restore

mysql -uroot -p --default-character-set=utf8 newdbname < newdbname.sql
Copy after login

I originally wanted to change the default Language of phpMyAdmin to "中文-chinese simplified", but I tried modifying config.inc.php and config.default in the libraries directory. .php is useless, it doesn’t matter. After all, different people choose different encodings for the database. Some people always have to re-select the language, or let it default to "中文-chinese simplified-gb2312"!

Another guess is that the exported file encoding is gb2312, so you can consider converting gb2312 to utf8. This method is being tested.

The above is the detailed content of What should I do if the sql file exported by phpmyadmin is garbled?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template