Home > Database > Mysql Tutorial > body text

How to set MySQL database encoding under linux

黄舟
Release: 2017-08-04 14:01:05
Original
2653 people have browsed it

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.

How to set MySQL database encoding under linux


##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.

How to set MySQL database encoding under linux

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.

How to set MySQL database encoding under linux

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.

How to set MySQL database encoding under linux

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.

How to set MySQL database encoding under linux

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.

How to set MySQL database encoding under linux


##7. We can also execute the command To modify the encoding format of the database, you can use the command: alter database + database name default character set utf8 collate utf8_general_ci; to modify it to utf8 format. The specific operation is shown in the figure below.

How to set MySQL database encoding under linux


##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.

How to set MySQL database encoding under linux

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template