Solution:
In CentOS 7, modify MySQL database character encoding to UTF-8, which contains all the characters needed by all countries in the world, is an international code.
Specific operations:
1. Log on to the MySQL console.
Mysql-u root-p
Enter password
View the current mysql running status
Mysql> status
The last four encoding formats are changed, so UTF-8 is displayed. The default encoding type is latin1.
2. Modify the mysql configuration file
Default location:/etc/my. cnf
Go to The etc folder> vim my. cnf
The image is after I add the settings.
* My mysql does not have the [client] field. First, add the following code default-character-set = utf8 in the [client] section. (other setting statements are also mentioned online, it is a previous version, and is not used now)
* Add the following code in the [mysqld] section.
Character-set-server = utf8
Collation-server = utf8_general_ci
: Wq! # Save and exit
* Systemctl restart mysql. service # restart MySQL
* View the current mysql running status
Mysql> status
At this point all encoding should be UTF-8
Parameter description:
Haracter_set_client: character set of the client request data.
Character_set_connection: the character set that is received from the client and then transmitted.
Character_set_database: the character set of the default database. No matter how the default database changes, it is the character set. If no default database exists, set this parameter to the character set specified by character_set_server.
Character_set_filesystem: convert the file name in the operating system to this character set. That is, convert character_set_client to character_set_filesystem. The default value is binary.
Character_set_results: character set of the result set.
Character_set_server: the default character set of the database server.
Character_set_system: This value is always utf8. You do not need to set it. It stores the character set of system metadata.