Linux Learning CentOS (20)--centos6.4 Modify MySQL encoding method

Source: Internet
Author: User

By default, after logging in to MySQL, we can first view system variables through the show variables like command

For example, we can view the encoding of the database by show VARIABLES like '%character% ' command:

We can see that after the installation of MySQL, the default database encoding method is basically set to latin1 encoding, we need to modify it to UTF8 encoding format.

Here is the configuration file modified in the CentOS6.4 environment, the location of the configuration file may be different for other Linux distributions, but the content of the change is the same

1. First we need to find the MySQL master configuration file and then copy it to the/etc directory

[[Email protected] ~]  cp/usr/share/doc/mysql-server-5.1.  69/MY-LARGE.CNF/ETC/MY.CNF  

2. Modify the MY.CNF configuration file

① add Default-character-set=utf8 field under [client]

② add Default-character-set=utf8 field under [Mysqld]

③ plus init_connect= ' Set NAMES UTF8 ' (set to use UTF8 encoding when connecting to MySQL database, so that the MySQL database runs as UTF8)

3. Restart the MYSQLD service

[[Email protected] ~]  Service mysqld Restart

Then we landed in MySQL again and entered show variables like '%character% '; command to see how the current database is encoded, it turns out that the original latin1 has become UTF8 encoded.

If you make the above changes if you create a table directly from the database and then save it in Chinese, the question is taken out.

At this point we can use the following workaround: When creating the database, indicate that the default character set is UTF8

For example: Create DATABASE zkm Charset=utf8;

Linux Learning CentOS (20)--centos6.4 Modify MySQL encoding method

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.