Recommendation: how to convert data in MySQL4.1 _ MySQL

Source: Internet
Author: User
MySQL4.1 supports encoding, so it is a little troublesome to convert old data. However, you only need to pay attention to the following: 1. dump the original data before conversion. Generally, the original data is encoded in gb2312 format. the dump command is as follows: MySQLdump-u-pdatabaseadd-drop-tableextended-insertadd-drop-tab.

MySQL4.1 supports encoding, so it is a little troublesome to convert old data. However, you only need to pay attention to the following:

1. dump the original data before conversion. Generally, the original data is encoded in gb2312 format. the dump command is as follows:

MySQLdump-u-p database-add-drop-table-extended-insert

-Add-drop-table is used to avoid table creation during import.-extended-insert is used to prevent an SQL statement from being too large during import, think about how terrible it is to write thousands of records in one SQL statement.

Assume that the original database is gb2312 encoded and needs to be converted to utf8 encoding. the conversion between other encodings is similar.

2. modify the SQL file dumped by dump and use Emeditor or iconv to convert the file encoding to UTF-8. Be sure not to use the Unicode signature(bom#", because mysql.exe does not recognize it. Replace gbk_bin in the file with utf8_general_ci, replace gbk with utf8, and add:

Set names utf8;

With BOM, MySQL does not recognize the following errors:

     ERROR 1064 (42000) at line 1:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘???/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */’ at line 1

3. create a new MySQL database and then import the backup SQL statement. The import command is as follows:

Mysql-u-p database <dumpdata. SQL

4. if the file was previously exported, an error occurs during import:

     Got a packet bigger than ‘max_allowed_packet’ bytes orERROR 1153 (08S01) at line 616: Got a packet bigger than ‘max_allowed_packet’ by tes

Modify the maximum allowed package size of MySQL. edit my. ini and add the following statement in [MySQLd] (not used in this section:

Set-variable = max_allowed_packet = 10485760

Restart the MySQL service. here I set it to about 10 MB.

Here, the data import is basically complete, and the next step is to adjust the data according to different applications. generally, some systems support the data, but others do not, however, the adjustment methods are roughly divided into the following types:

1. add

     mysql_connect(….mysql_query(”set names ‘utf8′”);

This is the most common case, such as Brim.

2. set the encoding of the language file or template file to UTF-8. Note that you can directly convert the file encoding without worrying about the content, such as phpwind and mantis. The tool can be iconv.

3. modify the template file and set

     
     

Most of the original gb2312 encoding systems need to change this.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.