Garbled Characters During MySQL Data Import and Restoration

Source: Internet
Author: User

According to my experience, garbled characters occur when mysql imports or exports databases. This is generally caused by inconsistent document codes. Below I will introduce several solutions to garbled characters.

Solution:

Step 1: the database and table created during restoration are in utf8 format (utf8 is recommended, of course, either gbk or gb2312)

The Code is as follows:
 
Create database 'shegongku 'default character set utf8
Create table 'members '(
'Uid' mediumint (8) unsigned not null default '0 ',
'Username' varchar (15) not null default '',
'Password' varchar (40) not null default '',
'Salt' varchar (16) default NULL,
'Email 'varchar (60) not null default''
) ENGINE = MyISAM default charset = utf8;

Second, convert the encoding of the SQL file to utf8 format. You can use notepad2 or UltraEditor to convert the file, and then add a set names utf8 row to the first SQL file to save the file.


Part 3: import. In general, there will be no garbled characters. If you find the garbled characters again in the terminal cmd, this is not a database problem, but a display problem. Enter set names gbk in the terminal, in this way, Chinese characters are displayed normally.

Document Extension


Method 1: add the parameter-default-character-set = utf8 to solve the Garbled text problem.

Mysql-u root-p password <path_to_import_file-default-character-set = utf8

Method 2: solve the problem by importing garbled characters in the command line

1. use database_name;
2. set names utf8; (or other required encoding)
3. source example. SQL (SQL file storage path)

Method 3: directly paste the code in the SQL File

1. Open the SQLyog client software;
2. Locate the SQL editor and use NotePad to open the exported SQL file;
3. Copy all SQL statements in the file to the SQL editor and execute the SQL code;

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.