MySQL Query when garbled solution

Source: Internet
Author: User

A table when the display of normal Chinese, the establishment of the table after the query is garbled.

Mysql> Show tables;+----------------+|          Tables_in_test |+----------------+|????? || Table1 |+----------------+2 rows in Set (0.00 sec)

This typically occurs because of inconsistent encoding types on the client and server side.


View some of the encoding types on the client and server side:

mysql>  show variables like  "%char%";  +--------------------------+----------- -----------------+| variable_name             | value                       |+--------------------------+----------------------------+| character _set_client     | latin1                      | |  character_set_connection | latin1                      | |  character_set_database   | utf8                        | |  character_set_filesystem | binary                      | |  character_set_results    | latin1                      | |  character_set_server     | utf8                        | |  character_set_system     | utf8                        | |  character_sets_dir       | /usr/share/mysql/charsets/ |+--- -----------------------+----------------------------+8 rows in set  (0.00 sec) MySQL >


It can be seen from the server is UTF8, and the client is Latin, temporarily set the client code:

SET character_set_client= ' UTF8 ';  SET character_set_connection= ' UTF8 '; SET character_set_results= ' UTF8 ';


Check again to see if the table is garbled:

Mysql> Show tables; +-----------------+| Tables_in_test |+-----------------+| Student Information Sheet | | Table1 |+-----------------+2 rows in Set (0.00 sec)


This is the result of inconsistent coding, resolved:


1. If the database encoding inconsistency causes garbled characters, you need to modify the encoding type of the database:


Show CREATE database test;alter database test character set UTF8 COLLATE utf8_general_ci;


2. If this is a client problem, edit the configuration file and add the following line:

[Client]default-character-set=utf8


This article from "Small East elder brother" blog, declined reprint!

MySQL Query when garbled solution

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.