MySQL character collation (garbled) Problem Solving

Source: Internet
Author: User

MySQL character collation (garbled) Problem Solving

1. Create a MySQL database

1 CREATE DATABASE `test`2 CHARACTER SET 'utf8'3 COLLATE 'utf8_general_ci';

Create a table

 1 CREATE TABLE tp_wechatlocation 2 ( 3     ID INT NOT NULL AUTO_INCREMENT, 4     OpenID VARCHAR(50), 5     Latitude VARCHAR(10), 6     Longitude VARCHAR(10), 7     CityName VARCHAR(30), 8     CreateTime DATETIME, 9     PRIMARY KEY (ID)10 )ENGINE=INNODB DEFAULT CHARSET=utf8; 

Set the DEFAULT character sequence set for the table: ENGINE = innodb default charset = utf8

If the character sequence set of the default table is not added after data creation, the "CityName" garbled problem will occur.

  

2. Solution

You can use SQL statements to set the character sequence set of a table.

The DEFAULT encoding is utf8: alter table name default character set utf8 COLLATE utf8_general_ci;

Ansi (GBK or GB2312): alter database 'db _ name' default character set gbk COLLATE gbk_chinese_ci;

Modify the default character sequence set of a column:

Alter table tp_wechatlocation MODIFY CityName VARCHAR (30) character set utf8 COLLATE utf8_general_ci;

3. UTF8 display is not supported in dos

Set character sets in Linux:

Chinese settings: export LANG = zh_CN.GB2312
Export LANG = zh_CN.UTF-8

4. view the character sequence set

View the replica set of the current database: show variables like 'character % ';

Variable_name Value
-----------------------------------------------------------------------
Character_set_client utf8
Character_set_connection utf8
Character_set_database latin1
Character_set_filesystem binary
Character_set_results utf8
Character_set_server utf8
Character_set_system utf8
Character_sets_dir E: \ wamp \ bin \ mysql \ mysql5.5.20 \ share \ charsets \

View table: show create table yjdb;

This article permanently updates the link address:

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.