By default, after logging in to MySQL, we can first view system variables through the show variables like command
For example, we can view the encoding of the database by show VARIABLES like '%character% ' command:
We can see that after the installation of MySQL, the default database encoding method is basically set to latin1 encoding, we need to modify it to UTF8 encoding format.
Here is the configuration file modified in the CentOS6.4 environment, the location of the configuration file may be different for other Linux distributions, but the content of the change is the same
1. First we need to find the MySQL master configuration file and then copy it to the/etc directory
[[Email protected] ~] cp/usr/share/doc/mysql-server-5.1. 69/MY-LARGE.CNF/ETC/MY.CNF
2. Modify the MY.CNF configuration file
① add Default-character-set=utf8 field under [client]
② add Default-character-set=utf8 field under [Mysqld]
③ plus init_connect= ' Set NAMES UTF8 ' (set to use UTF8 encoding when connecting to MySQL database, so that the MySQL database runs as UTF8)
3. Restart the MYSQLD service
[[Email protected] ~] Service mysqld Restart
Then we landed in MySQL again and entered show variables like '%character% '; command to see how the current database is encoded, it turns out that the original latin1 has become UTF8 encoded.
If you make the above changes if you create a table directly from the database and then save it in Chinese, the question is taken out.
At this point we can use the following workaround: When creating the database, indicate that the default character set is UTF8
For example: Create DATABASE zkm Charset=utf8;
Linux Learning CentOS (20)--centos6.4 Modify MySQL encoding method