您好,登錄后才能下訂單哦!
一、查看當(dāng)前數(shù)據(jù)庫編碼
show variables like '%character%';
可以看到默認(rèn)的character_set_database編碼格式,這里能夠看到默認(rèn)的是latin1.
修改某個(gè)數(shù)據(jù)庫的編碼方式,進(jìn)入到該數(shù)據(jù)庫下面,如greenpass
修改為gb2312編碼方式:
mysql>use greenpass;
mysql>alter database greenpass character set gb2312;
mysql>show variables like 'character_set_database';
修改為utf-8編碼方式:
mysql> alter database greenpass character set UTF8;
mysql> flush privileges;
mysql>show variables like 'character_set_database';
二、修改配置文件
-在 [mysqld] 標(biāo)簽下加上以下內(nèi)容:
default-character-set = utf8
character_set_server = utf8
注意:如果此標(biāo)簽下已經(jīng)存在“default-character-set=GBK”類似的內(nèi)容,只需修改即可。
--在 [mysql] 標(biāo)簽下加上一行
default-character-set = utf8
--在 [mysql.server]標(biāo)簽下加上一行
default-character-set = utf8
--在 [mysqld_safe]標(biāo)簽下加上一行
default-character-set = utf8
--在 [client]標(biāo)簽下加上一行
default-character-set = utf8
重啟mysql服務(wù)即可。
3、數(shù)據(jù)庫編碼驗(yàn)證
進(jìn)入mysql后 執(zhí)行 :show variables like "% character %";
顯示結(jié)果應(yīng)該類似如下:
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
如果仍有編碼不是utf8的,請檢查配置文件,也可使用mysql命令設(shè)置:
set character_set_client = utf8;
set character_set_server = utf8;
set character_set_connection = utf8;
set character_set_database = utf8;
set character_set_results = utf8;
set collation_connection = utf8_general_ci;
set collation_database = utf8_general_ci;
set collation_server = utf8_general_ci;
另外:
建立數(shù)據(jù)庫時(shí)可以使用以下命令:
create database app_relation character set utf8;
use app_relation;
source app_relation.sql;
修改數(shù)據(jù)庫編碼的命令為:
alter database app_relation character set utf8;
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。