How to solve the MySQL garbled Problem

Source: Internet
Author: User

It can be said that the application of http://database.51cto.com/art/200426/12568.htm4.1has greatly changed the support for multiple languages, and many people have encountered the MySQL garbled problem. The following articles mainly solve the MySQL garbled problem, I hope it will bring you some help in this practical application.

After upgrading the database or importing local data to the VM, we suddenly found that the neat page was filled with various strange symbols.

This topic is specially opened on this site to introduce the causes of garbled characters in various situations and their solutions. The article will be updated occasionally. Stay tuned!

Subtitle:

Several common situations that may cause page garbled characters

Solutions to garbled Characters During data table conversion of different character sets

If you encounter MySQL garbled characters, you can gradually check the following issues:

1) Check whether your file storage encoding is consistent with the meta statement. If your file is stored in UTF-8 encoding but the meta is declared as gb2312, garbled characters will occur.

Solution: ensure that the page storage encoding is consistent with the meta statement. Open the file in notepad and "Save as". The following option is "encoding". Select the encoding method consistent with the meta declaration. (Note: The encoding declaration of meta should be placed in front of the title Tag; otherwise, the page may be blank .)

2) check whether the connection method set names is SET for your database connection. If you do not SET the connection method after MySQL 4.1, the insertion or query will be garbled.

Solution: after your database connection is followed by mysql_connect and before any query is executed, add the following sentence:

 
 
  1. Code:  
  2. mysql_query("SET NAMES utf8"); 

Utf8 needs to be set as needed.

3) Check whether your page code, meta declaration, and database connection method set names are consistent. If your page and meta are SET to gb2312, but set names utf8 in the program, it also causes garbled characters. The reason is that if the page is set to gb2312, the data in the form is submitted according to gb2312, but the program requires utf8 processing, and the result is garbled.

Solution: Make the page encoding, meta declaration, and database connection method set names consistent. Of course, the consistency here is not absolute. For example, MySQL utf8 is different from UTF-8 on the page, set the parameters according to your actual situation.

The above content is an introduction to MySQL's common garbled issues. I hope you will get some benefits.

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.