Discuss the actual solution to the MySQL garbled Problem

Source: Internet
Author: User
Tags mysql commands

In the previous articles, we analyzed the actual solution to the MySQL garbled problem. The following articles mainly describe the actual solution to the MySQL garbled problem, let's talk about how to solve the problem of Chinese garbled characters in MySQL data.

In my previous article, I have mentioned how to solve the problem of garbled characters in JSP to solve the problem of Chinese garbled characters in tomcat.) I also explained the problem of MySQL garbled characters in detail, all of them have solved the issue of garbled code in JSP, but some people still haven't solved the problem of MySQL garbled code, including myself, so I found some information, we hope this time we can completely solve the problem of garbled characters in the MySQL database.

A brilliant summary:

The VM is often changed, and the MySQL versions of different service providers are different. After data is imported, garbled characters and other problems cannot be displayed normally. I checked a lot of information and summarized my skills:

This is the case when importing data in WINDOWS.

Use MySQL commands

Run the doscommand to enter the MySQL bin directory and enter the MySQL-uroot-p Password Database Name <the database to be restored. For example, we need to name disk D as test. the SQL database is restored to the local test2 database:

MySQL-uroot-p password test2 is used for foreign hosts 4. x series, I feel better, no matter GBK and UTF-8 are not garbled, did not expect the new host MySQL is 5.0 version, after importing data, read out with Php is question mark, garbled text. I remember that I had a previous experience with Garbled text during Switching. The reason must be the difference between MySQL versions.

I had to check the information and found a solution. I added a set names UTF8 sentence after MySQL_connect to eliminate MySQL garbled characters in the UTF8 database. For GBK databases, I used SET NAMES GBK, the Code is as follows:

 
 
  1. $MySQL_mylink = MySQL_connect($MySQL_host, $MySQL_user, $MySQL_pass);   
  2. MySQL_query("SET NAMES 'GBK'"); 

The database character set is UTF-8.

The connection statement uses this

 
 
  1. MySQL_query("SET NAMES 'UTF8'");   
  2. MySQL_query("SET CHARACTER SET UTF8");   
  3. MySQL_query("SET CHARACTER_SET_RESULTS=UTF8'"); 

Another way is to change the MySQL character set if your machine is running, which is generally valid in MySQL 4 and MySQL 5. The above content is an introduction to the MySQL garbled solution. 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.