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

时间:2021-07-19 07:09:17

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

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

[client]
 prot=3306
[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(255),
cont text,
pdate datetime,
isleaf int #1-not leaf 0-leaf
);

insert into article values (null, 0, 1, '蚂蚁大战大象', '蚂蚁大战大象', now(), 1);
insert into article values (null, 1, 1, '大象被打趴下了', '大象被打趴下了',now(), 1);
insert into article values (null, 2, 1, '蚂蚁也不好过','蚂蚁也不好过', now(), 0);
insert into article values (null, 2, 1, '瞎说', '瞎说', now(), 1);
insert into article values (null, 4, 1, '没有瞎说', '没有瞎说', now(), 0);
insert into article values (null, 1, 1, '怎么可能', '怎么可能', now(), 1);
insert into article values (null, 6, 1, '怎么没有可能', '怎么没有可能', now(), 0);
insert into article values (null, 6, 1, '可能性是很大的', '可能性是很大的', now(), 0);
insert into article values (null, 2, 1, '大象进医院了', '大象进医院了', now(), 1);
insert into article values (null, 9, 1, '护士是蚂蚁', '护士是蚂蚁', now(), 0);

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

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