Practical solutions to mysql exporting Chinese garbled characters and phpmyadmin importing Chinese garbled characters_PHP tutorial

WBOY
Release: 2016-07-21 15:37:17
Original
670 people have browsed it

I have never used phpmyadmin. I also use navicat on this machine. I always feel that phpmyadmin is slow. This time it didn't work. I didn't have a separate host, so I had to use the phpmyadmin provided by others.

Step one: Export local data to sql file. I thought this was a trivial matter for Navicat. Directly right-click on the database and "dump sql" (as shown in Figure 1), and wow, the export is successful in more than ten seconds.

(Figure 1: Convert the entire database to sql under navicat)

When I opened it with notepad, I was dumbfounded. Chinese is all gibberish. What's going on? I searched a bit and found out what connection properties to change. Doesn't work. Try to dump sql on a single table, hey, Chinese is normal. But with 82 tables, I’m not exhausted from dumping them one by one. no. It seems that I can only abandon my beloved navicat. I remembered that there is a mysqldump so I can try it. Run -C:Documents and SettingsAdministrator>mysqldump -uroot -p123 ttg>ttgbk2.sql. When I opened it, it was still garbled. Not yet. well. . Search, change to the following and add the specified character set

C:Documents and SettingsAdministrator>mysqldump -uroot -p123 --default-character-set=gbk ttg>ttgbk2.sql. Open it and take a look. Hey that's it.

Step 2: Open phpmyadmin provided by the virtual host. Import and select the file ttgbk2.sql. Click Execute. That speed, ugh. . . An error was reported after a while. An access denied error occurred when executing lock tables tablename write. It turned out that I was a virtual host user and did not have the permission to lock tables. When I opened SQL, I saw that there was indeed a lock tables option. If you don't have permission, don't use this. I searched online and said that --skip-lock-tables was added, and I thought it was good. It should be this "skip lock table"

Add the -skip-lock-tables option when mysqldump, then the command line becomes
C:Documents and SettingsAdministrator>mysqldump -uroot -p123 --default-character-set=gbk --skip-lock -tables ttg>ttgbk3.sql.
The result was disappointing, there are still lock tables.
After looking at mysqldump --help
, I realized that --skip-lock-tables is not used during backup. Make reading and writing possible. But if you don’t want the export to have lock-tables (because you don’t have permission when importing, haha), you should use add-locks=false. These are two concepts. The correct one is as follows
C:Documents and SettingsAdministrator>mysqldump -uroot -p123 --default-character-set=gbk ttg --add-locks=false>ttgttg3.sql.

My exported version is in asni format when opened in Notepad.

Go to phpmyadmin again to import. The result is an error after importing 3 tables. The mysql statement reports an error. At first glance, the Chinese characters are garbled. . . . . Close to collapse.

Look for the reason again. Change "MySQL connection proofreading" to gbk-chinese-ci, and change the language to 中文-chinese simplified (Figure 2). Then change the "file encoding" during import to "gbk" (the default is utf-8, of course, the encoding of the corresponding sql file is ansi when opened with notepad) (Figure 3). Try again. . . .

Practical solutions to mysql exporting Chinese garbled characters and phpmyadmin importing Chinese garbled characters_PHP tutorial

(Picture 2: Modify link proofreading and language)

(Picture 3: Modify the character set of the file to gbk)

Finally all tables were imported successfully. Open a table containing Chinese characters, and the fields display normally.

2 points of experience:

1. Database coding belongs to database coding. Just make sure that the connection proofreading is consistent with the database encoding.

2. SQL file encoding belongs to file encoding. It is best to ensure that the file encoding selected when importing is consistent with the encoding used in the database.

These are 2 encoding issues.

I’m impressed with you mysql. From the time I knew you had this coding problem to now, you are still like this. This question still confuses many people. When will it be internationalized like sqlserver?

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/321967.htmlTechArticleI have never used phpmyadmin. I also use navicat on this machine. I always feel that phpmyadmin is slow. This time it didn't work. I didn't have a separate host, so I had to use the phpmyadmin provided by others. Step one: Local...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!