How to modify the default Character Set of mysql
From: http://database.51cto.com/art/201010/229167.htm
Can the default mysql Character Set be modified? The answer is yes. Here are two ways to modify the default Character Set of mysql. I hope you can learn about the default Character Set of mysql.
(1) The simplest modification method is to modify the character set key value in mysql's my. ini file,
For example, default-character-set = utf8
Character_set_server = utf8
After modification, restart the mysql service, service mysql restart
Use mysql> show variables like 'character % '; Check that the database encoding 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 default Character Set of mysql 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 ;
Generally, even if you set the default mysql Character Set of the table to utf8 and send the query by UTF-8 encoding, you will find that the database is still garbled. The problem lies in the connection layer. The solution is to execute the following statement before sending the query:
- SET NAMES 'utf8';
It is equivalent to the following three commands:
- SET character_set_client = utf8;
- SET character_set_results = utf8;
- SET character_set_connection = utf8;