本篇內(nèi)容主要講解“如何讓MYSQL徹底支持中文”,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來(lái)帶大家學(xué)習(xí)“如何讓MYSQL徹底支持中文”吧!
目前創(chuàng)新互聯(lián)已為上千多家的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)絡(luò)空間、網(wǎng)站托管、服務(wù)器租用、企業(yè)網(wǎng)站設(shè)計(jì)、萬(wàn)州網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長(zhǎng),共同發(fā)展。先將讓slack支持中文,方法可以看"linuxsir.org之Slackware討論區(qū)",然后重新編譯mysql,原來(lái)系統(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ù)庫(kù)中,創(chuàng)建中文支持表腳本如下,對(duì)字段加上字符集說(shuō)明
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ù)庫(kù)加個(gè)默認(rèn)字符集聲明GBK,就不用建表時(shí)候每個(gè)字段聲明了,這樣看起來(lái)簡(jiǎn)單流暢,沒(méi)有特殊的痕跡,建議多采用這種方法.
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徹底支持中文”有了更深的了解,不妨來(lái)實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)建站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!