Generally, after installing the mysql database, we find that the database does not support Chinese. This is a problem with the default encoding format of the database. In this article, we introduce how to modify the default encoding of the database to utf8.
1. First, we enter the mysql -u root -p command in the terminal window, and then enter the root account password to connect to the database. The specific operation is shown in the figure below.
##2. After connecting to the database, execute Command show variables like 'character%'; to view the encoding format of the database, you can see that the default encoding of the database and database server is: latin1 encoding. The specific operation is shown in the figure below.
3. Then we exit the database and modify the database configuration file my.cnf file. If this file is installed through rpm Generally in the /etc/ directory, the specific modified style is as shown in the figure below.
4. After the modification is completed, we save the configuration modification and then execute the command service mysqld restart. Restart the database. The specific operation is shown in the figure below.
5. Then we wait for the database to restart, reconnect to the database, and execute the command show variables like 'character%' ; View the changed encoding format. The specific display is shown in the figure below. You can see that it has been modified to utf8 encoding.
6. Of course, to view the encoding format of a certain database, we can execute the command show create database+database name ;The specific display is shown in the figure below.
##8. After the modification is completed, we again Execute the command show create database + database name to check whether the change is successful. You can see that it is already in utf8 format.
This article only introduces Linux The encoding format setting of the database is installed using rpm.
The above is the detailed content of How to set MySQL database encoding under linux. For more information, please follow other related articles on the PHP Chinese website!