Mysql garbled code ultimate solution _ MySQL

Source: Internet
Author: User
Mysql garbled code ultimate solution bitsCN.com
The ultimate solution for Mysql garbled code recently runs an SQL file in the Mysql database that comes with Linux. there is no problem in querying the database. you can see Chinese data, but in JSP page display but there is garbled, in spring configuration database connection URL, specify the encoding "characterEncoding = UTF-8", and the browser is the UTF-8 encoding, why is it garbled. Finally come to the conclusion that the original Linux database is not the UTF-8 encoding, after finishing, get the following solutions: the first solution: garbled problem is simply the database write read, when the webpage file is displayed, the encoding of several links is inconsistent. When writing garbled text: the encoding for writing data to the page extraction is inconsistent with that for writing data to the database: When the encoding used after reading is inconsistent with that used for writing data to the database: the encoding is inconsistent with the data read by the database. Obviously, only the three are unified: (take UTF-8 as an example)
1: The data encoding for page submission is UTF-8 (this can also be regarded as the display page encoding). 2: The encoding for database writing: alter database db default character set 'utf8' collate 'utf8-general-ci', 3: encoding used for database reading: mysql_query ("set names 'utf8'"); 4: display page code: Solution 2: Enter the MYSQL command line: mysql> alter database you_dbname default character set 'utf8'; mysql> SET character_set_client = 'utf8 '; mysql> SET character_set_connection = 'utf8' mysql> SET character_set_results = 'utf8' solution 3: (currently, only solutions to MySQL 5.0.16 garbled characters are available. Other versions are not tested .) 1 set phpMyAdmin Language: Chinese simplified (zh-utf-8) MySQL character set: UTF-8 Unicode (utf8) MySQL connection proofread: gbk_chinese_ci 2: Set it to gbk_chinese_ci when creating a database. 3. use SQL to create a table. ENGINE = MyISAM DEFAULT CHARSET = gbk; ENGINE = InnoDB DEFAULT CHARSET = gbk AUTO_INCREMENT = 40; 4. check whether the varchar (100) sorting attribute in the table structure is gbk_chinese_ci. if other types of sorting attributes are empty, add $ db-> query ("set character set gbk") to the code "); required for Linux, not for Windows
This is equivalent to Connection Character Sets and Collations.
BitsCN.com

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.