Five methods for MySQL to insert Chinese characters without garbled characters, and five methods for mysql to insert garbled characters

Source: Internet
Author: User

Five methods for MySQL to insert Chinese characters without garbled characters, and five methods for mysql to insert garbled characters

Method 1:
Log on to MySQL, first set names latin1, and then execute the SQL statement in the update statement or

mysql> set names latin1;mysql> source test.sql;

Method 2:
Specify set names latin1 in the SQL file; then log on to MySQL and execute the corresponding file

[root@localhost ~]# cat test.sql set names latin1;insert *****************;mysql> source test.sql;

Method 3:
Specify set names latin1 in the SQL file, and then use the MySQL command to import

[root@localhost ~]# mysql -uroot -p123456 test <test.sql

Method 4:
Implement -- default-character-set = latin1 by specifying the character set parameter of the MySQL Command

 [root@localhost ~]# cat test.sql insert *****************;[root@localhost ~]# mysql -uroot -p123456 --default-character-set=latin1 test <test.sql

Method 5: This method is recommended, but utf8 is recommended.
Set client and server parameters in the configuration file
That is, you can modify the module parameters of the my. cnf client to implement set names utf8 and take effect permanently.

[Client] default-character-set = utf8. You do not need to restart MySQL and log out of the current logon, log On again to [server] default-character-set = utf8 5.1 versions earlier than character-set-server = utf8 5.5

Database Table, program!
Copy codeThe Code is as follows:
Create database wyb default character set utf8 collate utf8_general_cli;

Character Set description summary table

Mysql> show variables like 'character _ set % '; | character_set_client | utf8 # client character set | character_set_connection | utf8 # Link character set | character_set_database | utf8 # database character set, specify the configuration file or when creating the table | character_set_results | utf8 # returned result character set | character_set_server | utf8 # server character set, configuration file, or database

This article is from the "crazy_sir" blog

Related Article

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.