Home Backend Development PHP Tutorial Practical solutions to mysql exporting Chinese garbled characters and phpmyadmin importing Chinese garbled characters_PHP tutorial

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

Jul 21, 2016 pm 03:37 PM
mysql phpmyadmin Chinese Garbled characters Actual combat import Export method of solve this

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...
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use MySQL backup and restore in PHP? How to use MySQL backup and restore in PHP? Jun 03, 2024 pm 12:19 PM

Backing up and restoring a MySQL database in PHP can be achieved by following these steps: Back up the database: Use the mysqldump command to dump the database into a SQL file. Restore database: Use the mysql command to restore the database from SQL files.

How to optimize MySQL query performance in PHP? How to optimize MySQL query performance in PHP? Jun 03, 2024 pm 08:11 PM

MySQL query performance can be optimized by building indexes that reduce lookup time from linear complexity to logarithmic complexity. Use PreparedStatements to prevent SQL injection and improve query performance. Limit query results and reduce the amount of data processed by the server. Optimize join queries, including using appropriate join types, creating indexes, and considering using subqueries. Analyze queries to identify bottlenecks; use caching to reduce database load; optimize PHP code to minimize overhead.

How to insert data into a MySQL table using PHP? How to insert data into a MySQL table using PHP? Jun 02, 2024 pm 02:26 PM

How to insert data into MySQL table? Connect to the database: Use mysqli to establish a connection to the database. Prepare the SQL query: Write an INSERT statement to specify the columns and values ​​to be inserted. Execute query: Use the query() method to execute the insertion query. If successful, a confirmation message will be output.

How to use MySQL stored procedures in PHP? How to use MySQL stored procedures in PHP? Jun 02, 2024 pm 02:13 PM

To use MySQL stored procedures in PHP: Use PDO or the MySQLi extension to connect to a MySQL database. Prepare the statement to call the stored procedure. Execute the stored procedure. Process the result set (if the stored procedure returns results). Close the database connection.

How to create a MySQL table using PHP? How to create a MySQL table using PHP? Jun 04, 2024 pm 01:57 PM

Creating a MySQL table using PHP requires the following steps: Connect to the database. Create the database if it does not exist. Select a database. Create table. Execute the query. Close the connection.

How to fix mysql_native_password not loaded errors on MySQL 8.4 How to fix mysql_native_password not loaded errors on MySQL 8.4 Dec 09, 2024 am 11:42 AM

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

The difference between oracle database and mysql The difference between oracle database and mysql May 10, 2024 am 01:54 AM

Oracle database and MySQL are both databases based on the relational model, but Oracle is superior in terms of compatibility, scalability, data types and security; while MySQL focuses on speed and flexibility and is more suitable for small to medium-sized data sets. . ① Oracle provides a wide range of data types, ② provides advanced security features, ③ is suitable for enterprise-level applications; ① MySQL supports NoSQL data types, ② has fewer security measures, and ③ is suitable for small to medium-sized applications.

How to delete data from MySQL table using PHP? How to delete data from MySQL table using PHP? Jun 05, 2024 pm 12:40 PM

PHP provides the following methods to delete data in MySQL tables: DELETE statement: used to delete rows matching conditions from the table. TRUNCATETABLE statement: used to clear all data in the table, including auto-incremented IDs. Practical case: You can delete users from the database using HTML forms and PHP code. The form submits the user ID, and the PHP code uses the DELETE statement to delete the record matching the ID from the users table.

See all articles