提要系統自帶的mysql默認字符集不是gbk因此給數據庫的推廣應用以及中文程序的開發帶來極大的不便在沒完沒了的GBK和UTF的轉換過程中消耗了我們無數的精力以及系統的資源經過摸索嘗試解決了中文支持問題經驗與大家分享一下
先將讓slack支持中文方法可以看 之Slackware討論區然後重新編譯mysql原來系統mysql的要先用卸載
login:root
shell> removepkg mysql
shell> groupadd mysql
shell> cd /app
shell> mkdir mysql
shell> chmod
mysql
shell> useradd
G mysql
s /bin/bash –p /app/mysql mysql
shell> chown
R mysql
mysql mysql
下載mysqlxx
shell> gunzip < mysql
VERSION
tar
gz | tar
xvf
shell> cd mysql
VERSION
shell> CFLAGS=
O
mcpu=pentium
\
CXX=gcc \
XXFLAGS=
O
mcpu=pentium
felide
constructors
\
/configure
prefix=/app/mysql \
with
charset=gbk \
with
extra
charsets=
gbk gb
big
utf
\
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 根據CPU類型優化編譯
可以讓你的mysq表現更好!可選項目很多
i
i
i
i
pentium
pentium
mmx
pentiumpro
pentium
pentium
pentium
k
k
k
athlon
athlon
tbird
athlon
athlon
xp
athlon
mp
winchip
c
winchip
c
shell> make
錯誤時候
shell> make clean
再回上一步
shell> make install
shell> cp support
files/f /etc/f
shell> cd /app/mysql
shell> bin/mysql_install_db
user=root
shell> chown
R root
shell> chown
R mysql var
shell> chgrp
R mysql
shell>
/bin/mysqld_safe
user=root
default
character
set=gbk &
shell>
/bin/mysqladmin
u root password
new
password
shell>
/bin/mysql
u root
default
character
set=gbk
p
mysql> status
Server characterset: gbk
Db characterset: gbk
Client characterset: gbk
Conn
characterset: gbk
看見characterset全是gbk就算成功了
在UTF
字符集的老數據庫中
創建中文支持表腳本如下
對字段加上字符集說明
CREATE TABLE `test`
`cn` (
`zh` CHAR(
) CHARACTER SET gb
COLLATE gb
_chinese_ci NOT NULL
`中文` INT(
) NOT NULL
)
ENGINE = MYISAM;
注:CHARACTER SET 寫GB
和gbk都可以
gbk優於gb
對於新創建的數據庫加個默認字符集聲明GBK就不用建表時候每個字段聲明了這樣看起來簡單流暢沒有特殊的痕跡建議多采用這種方法
mysql> CREATE DATABASE dbCN DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci;
CREATE TABLE `dbCN`
`cn` (
`zh` CHAR(
) NOT NULL
`中文` INT(
) NOT NULL
)
ENGINE = MYISAM;
mysql> insert into cn values(
真的?
);
注:如果這些腳本用bin/mysql命令行是輸入不了可以 用mysql query Browser或者編程執行
shell> bin/mysql
u root
default
character
set=gbk
p
mysql>use test
mysql> select * from cn;
+
+
+
| zh | 中文 |
+
+
+
| 真的?|
|
+
+
+
row in set (
sec)
最後修改啟動文件/etc/rcd/rcmysqld
改路徑/app/mysql/bin/mysqld_safe
改路徑/app/mysql/var/webpid
/app/mysql/bin/mysqld_safe 後面加入 user=root defaultcharacterset=gbk
From:http://tw.wingwit.com/Article/program/MySQL/201311/29513.html