本篇內(nèi)容主要講解“如何讓MySQL徹底支持中文”,感興趣的朋友不妨來看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“如何讓MYSQL徹底支持中文”吧!
創(chuàng)新互聯(lián)公司主要從事網(wǎng)站設(shè)計(jì)、網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)阜城,十余年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):18980820575
先將讓slack支持中文,方法可以看"linuxsir.org之Slackware討論區(qū)",然后重新編譯mysql,原來系統(tǒng)mysql的要先用卸載.
login:root
shell>removepkgmysql
shell>groupaddmysql
shell>cd/app
shell>mkdirmysql
shell>chmod744mysql
shell>useradd-Gmysql-s/bin/bash–p/app/mysqlmysql
shell>chown-Rmysql.mysqlmysql
下載mysql4.x.x
shell>gunzip
shell>cdmysql-VERSION
shell>CFLAGS="-O3-mcpu=pentium3"\
CXX=gcc\
XXFLAGS="-O3-mcpu=pentium3-felide-constructors"\
./configure--prefix=/app/mysql\
--with--charset=gbk\
--with-extra-charsets="gbkgb2312big5utf8"\
--with-unix-socket-path=/etc/mysql.sock\
--enable-local-infile\
--enable-thread-safe-client\
--enable-assembler\
--with-client-ldflags=-all-static\
--with-mysqld-ldflags=-all-static
//-mcpu根據(jù)CPU類型優(yōu)化編譯,可以讓你的mysq表現(xiàn)更好!可選項(xiàng)目很多:i386,i486,i586,i686,pentium,pentium-mmx,pentiumpro,pentium2,pentium3,pentium4,k6,k6-2,k6-3,athlon,athlon-tbird,athlon-4,athlon-xp,athlon-mp,winchip-c6,winchip2,c3.
shell>make
------------------------------------------
錯(cuò)誤時(shí)候
shell>makeclean
再回上一步
-------------------------------------------
shell>makeinstall
shell>cpsupport-files/my-medium.cnf/etc/my.cnf
shell>cd/app/mysql
shell>bin/mysql_install_db--user=root
shell>chown-Rroot.
shell>chown-Rmysqlvar
shell>chgrp-Rmysql.
shell>./bin/mysqld_safe--user=root--default-character-set=gbk&
shell>./bin/mysqladmin-urootpassword'new-password'
shell>./bin/mysql-uroot--default-character-set=gbk-p
mysql>status
...
Servercharacterset:gbk
Dbcharacterset:gbk
Clientcharacterset:gbk
Conn.characterset:gbk
....
看見characterset全是gbk就算成功了.
怎樣讓MYSQL徹底支持中文
--------------------------------------------
在UTF8字符集的老數(shù)據(jù)庫中,創(chuàng)建中文支持表腳本如下,對(duì)字段加上字符集說明
CREATETABLE`test`.`cn`(
`zh`CHAR(10)CHARACTERSETgb2312COLLATEgb2312_chinese_ciNOTNULL,
`中文`INT(11)NOTNULL
)
ENGINE=MYISAM;
注:CHARACTERSET寫GB2312和gbk都可以,gbk優(yōu)于gb2312.
對(duì)于新創(chuàng)建的數(shù)據(jù)庫加個(gè)默認(rèn)字符集聲明GBK,就不用建表時(shí)候每個(gè)字段聲明了,這樣看起來簡(jiǎn)單流暢,沒有特殊的痕跡,建議多采用這種方法.
mysql>CREATEDATABASEdbCNDEFAULTCHARACTERSETgbkCOLLATEgbk_chinese_ci;
CREATETABLE`dbCN`.`cn`(
`zh`CHAR(10)NOTNULL,
`中文`INT(11)NOTNULL
)
ENGINE=MYISAM;
mysql>insertintocnvalues("真的?",1);
注:如果這些腳本用bin/mysql命令行是輸入不了,可以用mysqlqueryBrowser,或者編程執(zhí)行.
-------------------------------------------
shell>bin/mysql-uroot--default-character-set=gbk-p
mysql>usetest
mysql>select*fromcn;
+--------+------+
|zh|中文|
+--------+------+
|真的?|1|
+--------+------+
1rowinset(0.00sec)
---------------------------------------------
最后修改啟動(dòng)文件/etc/rc.d/rc.mysqld
改路徑/app/mysql/bin/mysqld_safe
改路徑/app/mysql/var/web.pid
/app/mysql/bin/mysqld_safe后面加入--user=root--default-character-set=gbk
到此,相信大家對(duì)“如何讓MYSQL徹底支持中文”有了更深的了解,不妨來實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!