How to Avoid MySQL garbled characters

Source: Internet
Author: User

How to avoidMySQLGarbled

To avoid garbled characters when the MySQL content in the database is displayed on the webpage, you can use the following methods to check and change the character set in MySQL ).

CheckMySQLText code settings in

In the MySQL environment, enter the following MySQL command to view the current characterset status. We can see that the default value of each text code is "lanten1 」.

Mysql> showvariables like 'character _ set % ';

Or

Mysql> status;

When creating a new database, you can use the following MySQL commands to set and confirm the preset text code of the database. For example, the default text code for the database of "mydb" is set to the ten-dollar code of "UTF-8.

Mysql> createdatabaase mydb default Character Set utf8;

Mysql> showcreate database mydb;


Edit/Etc/My. CNFFiles

Edit the character set in the/etc/My. CNF file and save it. For example, the text code is set to a-digit "UTF-8.

[Client]

Default-character-set = utf8

[Mysqld]

Default-character-set = utf8

Skip-character-set-client-handshake

Character-set-Server = utf8

Collation-Server =
Utf8_general_ci

Init-connect = set names utf8

In the configuration file, "Skip-character-set-client-handshake" is added to prevent internal MySQL transformation.


Manual restartMySQL

After the configuration is complete, manually stop and enable the MySQL service.

Stop Services manually

#/Usr/local/MySQL/bin/mysqladmin Shutdown

Manually enable the Service

#/Usr/local/MySQL/bin/mysqld_safe -- user = MySQL &

Finally confirm the set result, if all the set text code is changed to "UTF-8" ten thousand code, indicates that the set is complete.

Mysql> showvariables like 'character _ set % ';

Or

Mysql> status;

ByWww.435dns.comSort and post, reprinted please note

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.