Perfect conversion of MySQL character set to solve the problem of checking garbled characters in utf8 source file _ MySQL
Source: Internet
Author: User
Perfect conversion of MySQL character set solves the problem of viewing garbled characters in utf8 source files bitsCN. comMySQL has introduced the character set concept since mysql 4.1. Therefore, for mysql and earlier versions, their character sets are Latin1, so sometimes mysql character sets need to be converted, upgrade or downgrade the MySQL version, especially the MySQL version. to prevent the program from continuing to use the Latin1 character set before Discuz! The impact of version upgrades and the installation of SupeSite require conversion of character sets!
I have converted a lot of data and used a lot of methods. I personally feel that it is best to use the MySQL command to export and import the character set!
Now I will show you how to convert the MySQL character set in the illustrated format. because there are many character sets, we will mainly convert the two character sets: GBK and Latin1!
First, I will explain how to convert MySQL from GBK to Latin1 (if it is UTF8 or BIG5 conversion, you can replace GBK with the corresponding character set )! This issue occurs when MySQL is converted from MySQL4.1 and later
The version below MySQL4.1 is in the process! Some people can easily copy the files in the data directory of MySQL directly, especially those with host permissions. The problem is garbled! Of course, what I said requires you
You must have host permissions. VM users can set up local forums, download data to your local computer, import data to your local database, and convert character sets!
The current step is to export MySQL data. at the mysql command prompt (the linux system is the mysql command directory), enter the following export command:
Mysqldump-uroot-p -- default-character-set = gbk -- set-charset = latin1 -- compatible = mysql40 -- skip-opt discuz> discuz. SQL
1 (in windows) and (in linux)
In this way, you can easily export data from the MySQL database. at this time, the exported files are in the directory at the same level as the mysql command, that is, the bin directory, mySQL character set has been exported as Latin1! What we need to do now is to import data
Go to MySQL4.0!
Similarly, at the mysql command prompt in mysql 4.0 (in the command directory of mysql in linux), enter the following import command:
Mysql-uroot-p -- default-character-set = latin1-f discuz 3 (in Windows) and (in linux)
In this way, the character set is converted from GBK to Latin1, and MySQL is converted from MySQL 4.1 or later to MySQL!
Now I will explain how to convert the Latin1 character set to GBK!
Because only MySQL and later versions have the character set concept, if you want to convert the character set of MySQL from Latin1 to GBK, you must import it to a version later than MySQL, and then export it! There are many
Export to Latin1!
At the command prompt of MySQL4.0, enter the following export command:
Mysqldump-uroot-p -- default-character-set = latin1 -- set-charset = latin1 -- skip-opt discuz> discuz. SQL
Then import it to MySQL4.1 and enter the following import command:
Mysql-uroot-p -- default-character-set = latin1-f discuz Then, convert the character set in MySQL4.1 and enter the following export and import commands respectively:
Mysqldump-uroot-p -- default-character-set = latin1 -- set-charset = gbk -- skip-opt discuz> discuz. SQL
Mysql-uroot-p -- default-character-set = gbk-f newdiscuz If no problem exists, the conversion is complete! In fact, the whole process is relatively simple, but the process seems to be more troublesome, but the process is very simple and clear!
The following describes a problem that can easily occur during the import process!
The error "unknown command '/'" may occur during the import process. In fact, this error is caused by MySQL automatically adding a backslash to some traditional Chinese characters during the export process! To solve this problem, open
Backup SQL (discuz. SQL here). When an error is prompted, an error is prompted for the specific line. find the line and remove the backslash! In fact, you can use the Ultraedit text processing tools to batch process these backslashes.
! In my personal experience, there are a lot of strange user names, so it is easy to have a backslash, so as long as you correct those user names!
The above are some of my experiences in the data conversion process, which need to be improved in many places! BitsCN.com
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.