How to modify MySQL coding methods in CentOS (20)-CentOS 6.4-how to install and configure Mysql Databases in CentOS (13)-CentOS 6.4

Source: Internet
Author: User

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

 

 

 

  

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.