Home > Database > Mysql Tutorial > 解决mysql汉字存储问题_MySQL

解决mysql汉字存储问题_MySQL

WBOY
Release: 2016-06-01 13:30:50
Original
1145 people have browsed it

bitsCN.com

解决mysql汉字存储问题

 

在默认情况下,mysql是不能正确显示汉字的。

 

进入mysql 输入命令:

show variables like 'character_set_%';
Copy after login

查看字符集设置

+--------------------------+----------------------------+| 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/ |+--------------------------+----------------------------+
Copy after login

不能显示汉字就是因为character_set_database 的Value值为latin1;

修改命令为:

SET character_set_database = utf8 ;
Copy after login
(如果除filesystem外其他的value值不为utf8 也一律这样修改)。

修改后再次查看字符集配置确保如下:

解决mysql汉字存储问题_MySQL

修改之后,退出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;
Copy after login

 

 

然后你会发现可以成功显示汉字了;

解决mysql汉字存储问题_MySQL

 

bitsCN.com
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template