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