MySQL inserts Chinese non garbled code 5 ways

  • 2021-01-22 05:30:17
  • OfStack

Method 1:
Log in to MySQL, do set, names, latin1, and then update or execute SQL statements


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

Method 2:
Specify set names latin1 in SQL file; Then log in to MySQL and execute the appropriate file


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

Method 3:
Specify set names latin1 in SQL file; It is then imported through the MySQL command


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

Method 4:
This is done by specifying the character set parameter of the MySQL command --default-character-set=latin1


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

Approach 5: This approach is recommended, but ES37en8 is recommended
Set client - and server-side parameters in the configuration file
That is, by modifying the module parameters of my.cnf client, set names utf8 can be realized permanently


[client]
 default-character-set=utf8 
  Don't need to restart MySQL Log out of the current login and log in again 
[server]
 default-character-set=utf8 5.1 Previous version  
 character-set-server=utf8 5.5 version 

Library table, procedure!


CREATE DATABASE wyb  DEFAULT CHARACTER SET utf8 collate utf8_general_cli;

Character set meaning summary table


mysql> show variables like 'character_set%';
 
| character_set_client  | utf8  # Client character set       
| character_set_connection | utf8  # Linked character set       
| character_set_database | utf8  # The database character set is specified by the configuration file or at creation time       
| character_set_results | utf8  # Returns the resulting character set        
| character_set_server  | utf8  # Server character set, configuration file, or create the library table specified 

This post is from the ES54en_sir blog


Related articles: