Mysql資料庫插入的中文字段值顯示問號的問題解決

2021-09-08 19:31:32 字數 1980 閱讀 5663

最近我使用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

intprimary 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插入中文字段報錯

前言 在mysql中插入中文字段會報error 1366錯誤。網上找了些相同問題的解決方法,沒能解決我的問題,摸索了半天之後才初步解決問題,僅記錄下來,以便日後查閱,同時也方便遇到同樣問題的小夥伴解決。問題情景再現 利用status命令檢視mysql的運 況 發現server,db,client,c...

mysql中文字段排序

mysql中文排序失效解決方法convert name using gbk 當mysql使用的預設utf8編碼時,如果直接order by 中文字段排序,排序結果會不正確。將字段先轉換成gbk編碼再排序 convert 欄位名 using gbk convert 提供乙個在不同字符集之間轉換資料的方...

MySql資料庫無法插入中文字串

最近需要開發乙個註冊碼的登入,用到mysql資料庫,在將資料庫遷移到伺服器上發現向資料庫中插入中文字串時出現?亂碼我的解決方法 1 開啟mysql服務利用命令列檢視當前資料庫支援的預設編碼 輸入 show variables like char 可以看到當前資料庫的編碼 注意 character s...