1, display the current encoding information
Mysql>show variables like '%character% '
+--------------------------+----------------------------+
| variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | UTF8 |
| character_set_connection | UTF8 |
| Character_set_database | Latin1 |
| Character_set_filesystem | binary |
| Character_set_results | UTF8 |
| Character_set_server | Latin1 |
| Character_set_system | UTF8 |
| Character_sets_dir | /usr/share/mysql/charsets/|
+--------------------------+----------------------------+
8 rows in Set (0.01 sec)
2. Set the client code
Set under [MySQL] or [client] in the/etc/mysql/my.cnf file:
Default-character-set=utf8
Then, exit the MYQL client and reconnect to the MySQL server, which is the setting to take effect. The settings above affect three settings:
Character_set_client
Character_set_connection
Character_set_results
Attention:
The above settings are the same as in command line mode and do not require a restart
Mysql>set names UTF8;
Under Windows command line, execute the following command to solve the Chinese garbled problem
Mysql>set names GBK;
3. Set the server-side encoding
Under [Mysqld] in the/etc/mysql/my.cnf file, set:
Character-set-server=utf8
Restart the MySQL service, which is set to take effect. The settings above affect two settings:
Character_set_database
Character_set_server
4. Modify via MySQL command line
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 Character_set_system=utf8;
Mysql> set Collation_connection=utf8;
Mysql> set Collation_database=utf8;
Mysql> set Collation_server=utf8;
MySQL character encoding settings