Reasons and solutions for MySQL to save Chinese garbled characters

Source: Internet
Author: User
Tags mysql query php mysql mysql import

When you encounter this MySQL save Chinese garbled problem, look forward to find the MySQL save Chinese garbled reasons and solutions such an article can solve the problem is how exciting.
Perhaps 30% of programmers will choose their own Baidu, the results found that netizens have posted a lot like MySQL Chinese garbled, php MySQL Chinese garbled, mysql5.5 Chinese garbled, MySQL garbled, MySQL garbled problem, MySQL jsp garbled, MySQL JDBC garbled, MySQL query garbled, MySQL import data garbled, such as a series of problems, in the end, which is to find a solution to their own problems? 15% of programmers are ignorant, and the remaining 15% of programmers are groping or asking for help. 70% of programmers simply quit, do not move we are programmers, this waste of life things let others do, hehe.
In fact, MySQL garbled problem, said the complex is also very responsible, said simple and simple not!  The difference lies in understanding the nature of MySQL garbled reasons, this article from this point of view to let idiot programmers have mastered how to deal with this garbled problem. (1) The encoding of the website itself. It's not much to say, see if the settings are right, for example, I set the GBK to check if the code is GBK. (generally set by right-clicking properties of a file or setting up a project)
(2) Encoding of the database connection string. For example, in Java, I connect MySQL with the following statements: public static String drivername = "Com.mysql.jdbc.Driver";
public static String UserName = "root";
public static String userpasswd = "123456";
public static String DbName = "MyBook";
public static String URL = "jdbc:mysql://localhost/" + DbName + "? user="
+ UserName + "&password=" + userpasswd
+ "&USEUNICODE=TRUE&CHARACTERENCODING=GBK"; Class.forName (drivername). newinstance ();
Connection = (connection) drivermanager.getconnection (URL), as in the above code, bold is the part I want to say, can be set to the type of string you want, this is set to GBK, This is just an example of the Java language, other languages ASP, PHP principle is the same as the database string linked to the configuration of the character set, will not check the manual or Baidu a bit, this is easy to find, if Baidu can not find, that 360 dry he is also right.
(3) MySQL character set settings.  This is the focus, and is generally mistaken here and there is a MySQL garbled.  MySQL encoding settings can be divided into three settings: Database encoding, table encoding, and field encoding. A, the database encoding: in the SQLyog tool operation, right click on the database to change the database,

Set on it, idiot not idiot, simple is not simple. b, the table encoding: MySQL is very nonsense, the table level is also set the encoding, said I set the.
Right-click the table that you want to modify, click Change table For example, after the point is:
Point advanced Properties, table character encoding settings very idiot very simple, see the put. Remember to change the finished, be sure to click on the alter!  This button is easy to ignore, motherfucker SQLyog! C, the encoding of the field: MySQL is really very lame, the fields have encoding settings, or the above change table, but not point advanced properties. Look at the picture:

The default does not show, right is in the lower right corner! See the put, put the checkmark cancel the put, cancel after you see:

Finally see the field followed by the character encoding settings, his grandmother's bear, finally all look for the whole. Set the put. Remember to change the finished, be sure to click on the alter! This button is easy to ignore, motherfucker SQLyog!
Finally, one more trick: Show create table name create TABLE ' Wen ' (
' ID ' int (8) DEFAULT NULL,
' BookID ' int (8) DEFAULT NULL,
' title ' varchar (COLLATE) Gbk_bin DEFAULT NULL,
' Content ' Longtext COLLATE gbk_bin
) Engine=innodb DEFAULT charset=gbk collate=gbk_bin checksum=1 delay_key_write=1 row_format=dynamic

Source: >

Reasons and solutions for MySQL to save Chinese garbled characters

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.