Fix MySQL database garbled characters

Source: Internet
Author: User
How to solve MySQL database garbled characters: Haha. After searching, reading, and reading on the internet, I finally found a solution to mqsql database garbled characters. Why, don't ask me who is limited in knowledge and cannot understand the principle. I will not talk much about it. I 'd like to talk about how to solve the problem of MySQL database garbled characters !!! At the same time, write it down to avoid forgetting it in the future, and you have to search again. First I'm using the mysql-4.1.14 version. 1. Start mysqlquerybrowser, enter alter database 'test' default Character Set utf8 collate utf8_bin in it, and set the encoding of the test database to utf8. 2. modify the table encoding: alter table 'category' default Character Set utf8 collate utf8_bin or above is to change the category encoding of a table to utf8 3. modify the field encoding: Right-click the table in mysqlquerybrowser and click Edit table to modify or enter the code: alter table 'test' change 'dd' varchar (45) Character Set utf8 collate utf8_bin not null I am relatively lazy, so I chose the first method. Note: After completing the settings, restart the database. You can disable it in the service or MySQL administrator-servic control, in mysqlquerybrowser, right-click any database and choose Copy SQL to clipborad from the shortcut menu. If default character setutf8 is found, the setting is successful and the garbled code can be resolved. If not, find my. change the char in ini to utf8 4. on the JSP page, modify charset, <% @ page contenttype = "text/html; charset = UTF-8" %> (I have not tried this, I am in eclipse to build a main class to debug, it should be OK, but in eclipse that class to set the file as a UTF-8, just right click, properties can be seen) Here, my MySQL has no garbled code !! 5. In the JSP database connection statement, private string url = "JDBC: mysql: // localhost/" + db_name + "? User = "+ login_name +" & Password = "+ login_password +" & characterencoding = UTF-8 "; // characterencoding 6. if the JSP page does not specify the encoding for data submission, Garbled text will occur: in this case, you only need to add the request at the beginning of the page. setcharacterencoding ("UTF-8"); specify the submission can be summarized: first to judge JSP garbled is inserted after the database garbled, or JSP page just submitted on garbled, if JSP is garbled after receiving the data on the previous page, the character set is incorrect or the request is not added. setcharacterencoding ("UTF-8"); where 1, 2, 3 is the reason for the database

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.