在默认情况下,mysql是不能正确显示汉字的。
进入mysql 输入命令:show variables like 'character_set_%';
查看字符集设置
+--------------------------+----------------------------+
| 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 | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
不能显示汉字就是因为character_set_database 的Value值为latin1;
修改命令为:SET character_set_database = utf8 ; (如果除filesystem外其他的value值不为utf8 也一律这样修改)。
修改后再次查看字符集配置确保如下:
修改之后,退出mysql(quit),服务重启一下,
net stop mysql
net start mysql
重新进入mysql之后把之前建的table删除重新新建,建议使用文件备份之前的命令;
方法如下:
新建一个mysql.sql 用记事本编辑
use mysql;
create table students
(
id int unsigned not null auto_increment primary key,
name char(30) not null,
sex char(10) not null,
age tinyint unsigned not null,
tel char(13) null default "-"
);
insert into students values(NULL, "金开", "男", 20, "13811371377");
insert into students (name, sex, age) values("十元", "女", 20);
select * from students;
然后你会发现可以成功显示汉字了;