In the previous article, I have recorded the process of installing mysql under CentOS (CentOS for Linux (13)-installation and configuration of Mysql database under CentOS ), however, when we try to back up data in the database or import SQL files to our database, we may encounter Encoding Problems, when installing mysql in windows, we can select the encoding method of the entire database during installation (usually set to utf8 ), there will be no graphical interface for installing mysql in linux, so this article will record how to modify MySQL encoding in Linux.
After logging on to mysql by default, We can first view the system variables using the show variable like command.
For example, you can run the show variable like '% character %' command to view the database encoding:
We can see that after mysql is installed, the default database encoding method is basically set to latin1 encoding method. At this time, we need to change it to utf8 encoding format.
The following is how to modify the configuration file in CentOS6.4. The configuration file may be in different locations in other Linux releases, but the changed content is the same.
1. First, we need to find the mysql master configuration file and copy it to the/etc directory.
[root@xiaoluo ~] cp /usr/share/doc/mysql-server-5.1.69/my-large.cnf /etc/my.cnf
2. Modify the my. cnf configuration file
① Add the default-character-set = utf8 field under [client]
② Add the default-character-set = utf8 field under [mysqld]
③ Add init_connect = 'set NAMES utf8' (SET utf8 encoding when connecting to the mysql database to run the mysql database as utf8)
3. Restart the mysqld service.
[root@xiaoluo ~] service mysqld restart
In this case, we log on to mysql again, and enter the show variables like '% character %' command to check the encoding method of the current database, it is found that the original latin1 has changed to the utf8 encoding method.
If the above changes are made, if the database directly creates a table and then stores the table in Chinese, the question mark is returned.
In this case, we can use the following solution: Specify the default Character Set utf8 when creating a database.
Example: create database xiaoluo charset = utf8;
You can clickBottom right cornerTo evaluate the content of the article.Follow buttonTo follow the latest developments in my blog. If the article content is helpful to you, do not forget to clickRecommendation buttonIf you have any questions about the content of the article, you can contact me by comment or by email: 501395377@qq.com/lzp501395377@gmail.com