This article describes in detail how to solve the problem of mysql Default character encoding and Chinese garbled characters. For more information, see.
This article describes in detail how to solve the problem of mysql Default character encoding and Chinese garbled characters. For more information, see.
MySQL Default encoding is Latin1, does not support Chinese, so how to modify the default encoding of MySQL, the following UTF-8 as an example to explain
After mysql is started, log on to mysql as the root user
Mysql> show variables like 'character % '; # display the code
+ -------------------------- + ---------------------------- +
| Variable_name | Value |
+ -------------------------- + ---------------------------- +
| Character_set_client | latin1 |
| Character_set_connection | latin1 |
| Character_set_database | latin1 |
| Character_set_filesystem | binary |
| Character_set_results | latin1 |
| Character_set_server | latin1 |
| Character_set_system | utf8 |
| Character_sets_dir |/usr/share/mysql/charsets/|
+ -------------------------- + ---------------------------- +
This is the default character encoding after installation (in the figure below, windows is similar)
It should be noted that there are many changes and there are many corresponding modification methods. The following is the simplest and most thorough method:
I. Windows
1. Stop the MySQL Service
2, in the installation directory of MySQL find my. ini, if not, copy the my-medium.ini as a my. ini
3. After opening my. ini, add default-character-set = utf8 under [client] and [mysqld], save and close
4. Start the MySQL Service
Ii. Linux
1. Stop MySQL Service (bin/mysqladmin-u root shutdown-p)
2. Find my under/etc. cnf, if not, copy the my-large.cnf under the support-files directory under the MySQL installation directory to/etc/and rename it to my. cnf
3. After opening my. cnf, modify the following, save and disable
Find the client configuration [client] and add it below
Default-character-set = utf8 default character set: utf8
Add in [mysqld]
Default-character-set = utf8 default character set: utf8
Init_connect = 'set NAMES utf8' (SET utf8 encoding for mysql connection to run utf8 for mysql database)
4. Start MySQL Service (bin/mysqld_safe &) and check the encoding display again.
Mysql> show variables like 'character % '; # display the code
+ -------------------------- + ---------------------------- +
| 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 |/usr/share/mysql/charsets/|
+ -------------------------- + ---------------------------- +
The modified encoding is displayed (in Solaris, similar to windows)
Very simple, this change once and for all, in the future MySQL All Related default encoding is UTF-8, create a new table without setting again