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.
- In the SQL file to be executed, the first one adds set names latin1;
- Importing with MySQL specified encoding
Mysql–uroot–p ' password '--default-charset-set=latin1 test < Test.sql;
Three MySQL Service side
- 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
- Export the Library and table creation statements to modify the encoding to UTF8
- Export all data
- Delete all libraries and data
- Create new libraries and tables with new built-in and database-built statements
- Import data
MySQL prevent Chinese garbled small method