The newly installed mysql server, because the default is latin encoding, often appears garbled under the linux server.
The coding design of mysql is relatively complex, involving the coding of servers, clients, databases, tables and table fields. To support Chinese, all encodings need to be set to UTF8.
1. Placement
vi /etc/my.cnf
[client] default-character-set = utf8 #Client sets UTF8 [mysqld] lower_case_table_names = 1 #Table names ignore case character-set-server = utf8 #Server set UTF8 collation-server = utf8_general_ci #utf8 and case-insensitive correction rules
View table encoding:
mysql> show create table green_app_info; +----------------+------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table --------------+ | green_app_info | CREATE TABLE `green_app_info` ( `id` int(11) NOT NULL AUTO_INCREMENT, `apptype` int(11) NOT NULL, `appid` int(11) NOT NULL, `name` char(128) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1064 DEFAULT CHARSET=utf8 | +----------------+------------------------------------------------------------------------------------------------------------------+ 1 row in set
Set database encoding:
alter database greennet character set utf8;
Check out the encoding:
mysql> show variables like '%character_set_%'; +--------------------------+---------------------------------------------------------+ | Variable_name | Value | +--------------------------+---------------------------------------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/local/mysql-5.5.39-linux2.6-x86_64/share/charsets/ | +--------------------------+---------------------------------------------------------+ 8 rows in set
All are set to UTF8, and then /etc/init.d/mysqld restart restarts, inserting Chinese is normal.
2. PDM setting table coding
1. Set table options
Database --> Edit Current DBMS
General --> MySQL 5.0 --> Script --> Table --> Options
Add the following content, set the table ENGINE, character encoding, proofreading rules:
ENGINE = %s : list = BDB | HEAP | ISAM | InnoDB | MERGE | MRG_MYISAM | MYISAM, default = MYISAM DEFAULT CHARSET = %s : list = utf8 | gbk, default = utf8 COLLATE = %s : list = utf8_bin | utf8_general_ci | gbk_bin | gbk_chinese_ci, default = utf8_bin
2. Set table characters
Double-click the table --> select UTF8 encoding