mysql 中文乱码

阅读更多

新安装的mysql服务器,由于默认的是latin编码,在linux服务器下经常出现乱码。

mysql的编码设计的比较复杂,涉及到服务器,客户端,数据库,表及表字段编码。为了支持中文,需要将所有的编码设置为UTF8。

 

一. 配置 

vi /etc/my.cnf

 

[client]
default-character-set = utf8 			#客户端设置UTF8

[mysqld]
lower_case_table_names = 1				#表名忽略大小写
character-set-server = utf8 			#服务端设置UTF8
collation-server = utf8_general_ci		#utf8且大小写不敏感的校正规则

 

查看表编码:

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

 

设置数据库编码:

alter database greennet character set utf8; 

 

查看编码:

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

全部设置成UTF8,然后 /etc/init.d/mysqld restart  重启,插入中文正常。

 

二. PDM设置表编码

1. 设置表选项

Database --> Edit Current DBMS

General --> MySQL 5.0 --> Script --> Table --> Options 

添加如下内容,设置表ENGINE,字符编码,校对规则:

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. 设置表字符

双击表 --> 选中UTF8编码

mysql 中文乱码_第1张图片 

 

 

 

 

 

 

  • mysql 中文乱码_第2张图片
  • 大小: 32.6 KB
  • 查看图片附件

你可能感兴趣的:(mysql乱码,powerdesigner)