Solve the garbled problem caused by inconsistent MySQL Codes

Source: Internet
Author: User

When using MySQL, garbled characters are often caused by inconsistent encoding. The following information about MySQL Data Encoding is provided, which may be helpful.

I. MySQL encoding mechanism:

1. Database-level encoding: databases with different codes can be created on the database server. encoding must be specified when the database is created;

2. Table-level encoding: You can create tables of different encodings in the same database. You must specify the encoding when creating a table. The encoding is used by default during user connection;

3. Table field-level encoding: fields of different codes can be created in the same table. The default value is the table encoding. You must specify a special encoding for the field, the encoding format must be explicitly specified in the field;

4. encoding used to establish a database connection: You can specify the encoding when establishing a database connection. The default encoding is the server configuration.

II. General causes of garbled characters:

1. The encoding used when establishing the database connection is incorrect: for example, the database encoding is UTF-8, And the encoding format is not specified when the data is connected, it will often cause garbled problem, the normal solution should be to specify the encoding jdbc: mysql: // localhost: 3306/zhuo.pdf in driverURL? UseUnicode = true & characterEncoding = UTF-8

2, The table encoding and driverURL specified encoding inconsistency caused by garbled problem for example: The table encoding is latin1, driverURL specified encoding is UTF-8, when saving, the system will prompt that the error data is saved. The solution is to use the same encoding.

3. garbled problem caused by inconsistent table encoding and table field encoding. For example, the table encoding is UTF-8 and the field in the table is latin. This encoding problem is complicated to deal, it is recommended to unify the encoding format. If you are interested, you can study it in depth.

Iii. Cases

1, Spring, Hibernate, Struts and Proxool, using MySQL database garbled problem solving: If the table and the field encoding are consistent UTF-8, in Proxool configuration specified configuration item, you can solve the garbled problem jdbc: mysql: // localhost: 3306/zhuoworkflow? UseUnicode = true & characterEncoding = UTF-8

2, Spring, Struts and iBatis, using MySQL database garbled problem solving: If the table and field encoding are consistent UTF-8, In the attribute file configuration specified configuration item, you can solve the garbled problem jdbc: mysql: // localhost: 3306/bcq? UseUnicode \ = true & characterEncoding \ = UTF-8

3, Linux using MySQL built-in backup tools to convert different encoding formats of table data if the source table encoding format is latin1, the target table encoding format is UTF-8, in Linux, you can use the following command to convert mysqldump-C-h $ {source_host}-u $ {source_username}-p $ {source_password} -- default-character-set = latin1 source_database source_tablename | sed-e's/latin1/utf8/'| mysql-u $ {local_username}-p $ {local_password} local_tablename

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.