MySQL prevent Chinese garbled small method

Source: Internet
Author: User
Tags mysql client

MySQL Character Set introduction

Includes two-part character set character and proofing rules collation

Character sets are used to define how the MySQL string is stored

Proofing rules are the way to define a comparison string

If the database has more than one language, use UTF8, three bytes per kanji

If only support Chinese, use GBK, both Chinese and English are occupied 2 bytes

View MySQL's character set

character Set  Charset;

View existing database encoding settings

Mysql>Show variables like '%chara%';|Character_set_client|UTF8 Client||Character_set_connection|UTF8 Client Connection Character set||Character_set_database|UTF8 Database Character Set||Character_set_filesystem| binary                        ||Character_set_results|UTF8 client Returns the result character set||Character_set_server|UTF8 Server Character Set||Character_set_system|Utf8|

If MySQL is not specified, the client's character set is generally consistent with the system

Summary of preventing garbled methods

The idea of not garbled:

Linux system Client Service side Library table program

Need to control the above process coding consistency, prevent garbled

To view the encoding settings:

 like '%Chara%';

A Linux Systems

[[email protected] ~] /etc/sysconfig/i18nlang="en_US. UTF-8"Sysfont=" Latarcyrheb-Sun16 "

Two MySQL Client

Log in MySQL first do set names latin1; The character setting here is to view the method according to the character encoding to insert the table: (Show create TABLE TableName \g), then execute the UPDATE statement, or insert Chinese.

    1. In the SQL file to be executed, the first one adds set names latin1;
    2. Importing with MySQL specified encoding

Mysql–uroot–p ' password '--default-charset-set=latin1 test < Test.sql;

Three MySQL Service side

    1. Specify the encoding restart in the config file my.cnf to take effect permanently
[Client]default-character-Set=UTF8[MySQL]default-character-Set=UTF8[mysqld]default-character-Set=UTF8 (5. Versions prior to 1)character-Set-Server=UFT8 (suitable for 5.5) Chinese or choose UTF8

Four Libraries and tables

Specifying the default character encoding when creating libraries and tables

CREATE DATABASE IF  not EXISTS default charset UTF8 COLLATE utf8_general_ci; Create Table varchar (notnulldefault"default charset UTF8;
For tables with existing data, the idea of modifying the character set

Example: Latin1=>utf8

    1. Export the Library and table creation statements to modify the encoding to UTF8
    2. Export all data
    3. Delete all libraries and data
    4. Create new libraries and tables with new built-in and database-built statements
    5. Import data

MySQL prevent Chinese garbled small method

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.