Mysql数据库插入的中文字段值显示问号的问题解决

时间:2023-03-08 23:47:10
Mysql数据库插入的中文字段值显示问号的问题解决

最近我使用myeclipse连接mysql数据库查询表中的数据,表中字段值为中文的字段显示问号,查了很多资料将解决方法总结如下:

步骤一:修改mysql数据库的配置文件my.ini或者my-default.ini

[client]
prot=
[mysql]
default-character-set=GBK
[mysqld]
default-character-set=utf8
collation-server=utf8_general_ci

步骤二:创建数据库的时候指定数据库的编码格式,比如下面的例子展示的这样

create database bbs DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

use bbs;

create table article
(
id int primary key auto_increment,
pid int,
rootid int,
title varchar(),
cont text,
pdate datetime,
isleaf int #-not leaf -leaf
); insert into article values (null, , , '蚂蚁大战大象', '蚂蚁大战大象', now(), );
insert into article values (null, , , '大象被打趴下了', '大象被打趴下了',now(), );
insert into article values (null, , , '蚂蚁也不好过','蚂蚁也不好过', now(), );
insert into article values (null, , , '瞎说', '瞎说', now(), );
insert into article values (null, , , '没有瞎说', '没有瞎说', now(), );
insert into article values (null, , , '怎么可能', '怎么可能', now(), );
insert into article values (null, , , '怎么没有可能', '怎么没有可能', now(), );
insert into article values (null, , , '可能性是很大的', '可能性是很大的', now(), );
insert into article values (null, , , '大象进医院了', '大象进医院了', now(), );
insert into article values (null, , , '护士是蚂蚁', '护士是蚂蚁', now(), );

步骤三:我的myeclipse的编码方式和创建的web项目的编码方式都是gbk;
查询结果如下:

Mysql数据库插入的中文字段值显示问号的问题解决