Reasons and solutions for saving Chinese garbled characters in mysql

Source: Internet
Author: User
Tags php mysql


When you encounter the problem of saving Chinese garbled characters in mysql, It is very exciting to find the reason and solution for saving Chinese garbled characters in mysql.
Maybe 30% of programmers choose Baidu, the results showed that the user had posted many Chinese garbled characters similar to mysql, php mysql Chinese garbled characters, mysql5.5 Chinese garbled characters, mysql garbled characters, mysql jsp garbled characters, mysql jdbc garbled characters, mysql query garbled characters, mysql imports garbled data and other issues, which of the following solutions can solve your own problems? 15% of the programmers will be overwhelmed at a glance, and 15% of the remaining programmers will explore or ask for help. 70% of programmers simply don't do it. If you can't do it, you can still do it as a programmer. This kind of waste of life allows others to do it.
In fact, the problem of garbled mysql is complicated and very responsible. It is not easy to say! The difference lies in understanding the essential cause of mysql Garbled text. This article aims to let programmers master how to deal with this Garbled text. (1) website code. That's not much to say. Let's see if the settings are correct. For example, if I set the GBK, I will check whether the encoding is GBK. (Generally, you can right-click a file or set it when creating a project)
(2) encoding of the database connection string. For example, in java, the statements related to mysql connection are as follows: public static String driverName = "com. mysql. jdbc. Driver ";
Public static String userName = "root ";
Public static String userpassswd = "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); in the above Code, bold is what I want to talk about. You can set the desired string type. Here we set GBK, which is just an example of the java language, the principles of asp and php in other languages are the same. There are such database string links about character set configuration. You won't check the manual or Baidu. This is easy to find. If Baidu still cannot find it, that's right, too.
(3) mysql Character Set settings. This is the focus, and mysql garbled characters are usually incorrect here. Mysql encoding settings can be divided into three types: Database encoding, table encoding, and field encoding. A. Database encoding: In the sqlyog tool, right-click the database and click Change Database,

It's easy to set up. B. Table encoding: mysql sets the encoding at the table level.
Right-click the table for which you want to modify the encoding, and click Change table, as shown in the following figure:
The character encoding settings of the table are very simple. Remember to click Alter after modification! This button is easy to ignore. It's a fucking sqlyog! C. Field encoding: mysql is really bullshit. All fields have encoding settings, or the above table is changed, but no more advanced attributes. Figure:
 
It is not displayed by default, right in the lower right corner! Check the check box and cancel the check box. After the check box is canceled, you can see:
 
Finally, I saw the character encoding settings behind the field. his grandmother's Bear finally found all. Set. Remember to click Alter after modification! This button is easy to ignore. It's a fucking sqlyog!
Finally, let's try again: show create table name create table 'wen '(
'Id' int (8) default null,
'Bookid' int (8) default null,
'Title' varchar (200) 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
 

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.