Dealing with MySQL garbled problem under Linux (the following UTF8 for gb2312 is also possible)

Source: Internet
Author: User
Tags mysql code

Sometimes because the code needs to modify the MySQL code, Windows modification has a simple graphic interface, Linux people can refer to the following methods

The default login to MySQL allows you to view system variables and their values through the show variables statement.

Mysql> Show variables like '%character% ';

Description: The following are the settings under CentOS-6.2 (different versions may have some differences, such as the location of the files.) But the content of the settings should be the same)

1. Find the MySQL configuration file, copy to the ETC directory, the first step is very important

Copy the/usr/share/doc/mysql-server-5.1.52/my-large.cnf to the/ETC/MY.CNF.

Ready-to-use command: CP/USR/SHARE/DOC/MYSQL-SERVER-5.1.52/MY-LARGE.CNF/ETC/MY.CNF

2. Open MY.CNF to modify the encoding

Add Default-character-set=utf8 under [client]

Add Default-character-set=utf8 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 MySQL

Service mysqld Restart

Re-enter show variables like '%character% ';

Even if you make the above changes if you create a table directly from the database and then save it in Chinese, the question mark will be taken out. The workaround is to specify that the default character set is UTF8 when creating the database, such as:

Create DATABASE test default character set UTF8;

Dealing with MySQL garbled problem under Linux (the following UTF8 for gb2312 is also possible)

Related Article

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.