Two methods for modifying the mysql default character set are analyzed in detail


(1) the simplest modification method is to modify the key values of the character set in the my.ini file of mysql. Such as default character - set = utf8 character_set_server = utf8

After the modification, restart the mysql service, service mysql restart Using mysql > SHOW VARIABLES LIKE ‘character %’; Check and find that the database code has been changed to utf8

+--------------------------+---------------------------------+ 
| Variable_name | Value | 
+--------------------------+---------------------------------+ 
| character_set_client | utf8 | 
| character_set_connection | utf8 | 
| character_set_database | utf8 |
| character_set_filesystem | binary | 
| character_set_results | utf8 | 
| character_set_server | utf8 | 
| character_set_system | utf8 | 
| character_sets_dir | D:"mysql-5.0.37"share"charsets" | 
+--------------------------+---------------------------------+ 

(2) another way to modify the mysql default character set is to use the mysql command

mysql> SET character_set_client = utf8 ;
mysql> SET character_set_connection = utf8 ; 
mysql> SET character_set_database = utf8 ; 
mysql> SET character_set_results = utf8 ; 
mysql> SET character_set_server = utf8 ; 
mysql> SET collation_connection = utf8 ;
mysql> SET collation_database = utf8 ; 
mysql> SET collation_server = utf8 ; 

1. Even if you set the mysql default character set of the table to utf8 and send the query through the UTF-8 encoding, you will find that the data stored in the database is still scrambled. The problem lies in this connection connection layer. The solution is to execute 1 below before sending the query:

SET NAMES 'utf8';

It is equivalent to the following three instructions:

SET character_set_client = utf8;
SET character_set_results = utf8; 
SET character_set_connection = utf8;