Comprehensive Analysis of MySQL database Encoding Problems

Source: Internet
Author: User

MySQL Comprehensive Analysis of database coding problemsMySQL database 4.1 is a watershed, and 4.1 directly supports Unicode, which is not supported in the following versions. MySQL JDBC driver 3.0.16 is also a watershed. Version 3.0.16 will take the database encoding and convert it according to the encoding. This method is the same as that of oracle JDBC driver. For example, if your database is GBK encoded, The JDBC driver will convert the strings in the database to Unicode according to GBK and send them to JVM. Therefore, it is particularly important to correctly set the database encoding. MySQL JDBC driver3.0.16 or lower version is not, it is not so intelligent according to the database encoding to determine how to convert, it is always the default use of ISO8859-1, therefore, you must use characterencoding = GBK to force it to convert the string obtained from the database to Unicode Based on GBK. Therefore, what database version is used, whether it is 3.x, 4.0.x or 4.1.x, is not important to us. Note: 1) correctly set the database encoding, character sets of versions earlier than mysql4.0 are always the default ISO8859-1, and mysql4.1 will let you choose when installing. If you are going to use UTF-8, you need to specify the UTF-8 when creating the database (after the creation can also be changed, 4.1 or later versions can also separately specify the character set of the table) 2) use JDBC driver 3.0.16 or later versions, then you do not need to write characterencoding = UTF-8, if the database server uses UTF-8, then, JDBC transfers the database content to the JVM in UTF-8 format. However, if a database in the database server uses GBK encoding, the encoding will be inconsistent! In this case, you can? Characterencoding = GBK is forcibly transmitted to JVM using GBK encoding. Alternatively, you can convert the encoding of the entire MySQL database server to GBK. In MySQL, lartin1 is used by default, that is, ISO8859-1 character set encoding. This is an 8-bit encoding that applies to all Western European characters. It is not suitable for Chinese characters. The best and most common encoding format is UTF-8. In this case Unicode Character Set. For 8 For the Western European character set, it saves space and can effectively represent Chinese characters and other characters.   Therefore Set the database server to UTF-8 Format, put all MySQL The database is also set to UTF-8 Format, which is the best choice! All languages around the world can be well supported!  However, some common MySQL tools cannot display UTF-8 Chinese characters. For example, MySQL tools and MySQL-front software. However, MySQL in mymanger and command line can normally display UTF-8 Chinese characters. If you choose to use GBK, you should convert all the encoding formats of the database server and database to use GBK. Otherwise, problems may occur.

 

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.