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;