提要:系統自帶的MySQL默認字符集不是gbk,因此給數據庫的推廣應用以及中文程序的開發帶來極大的不便,在沒完沒了的GBK和UTF8的轉換過程中消耗了我們無數的精力以及系統的資源.經過摸索嘗試解決了中文支持問題,經驗與大家分享一下.
先將讓slack支持中文,方法可以看"Linuxsir.org 之Slackware討論區",然後重新編譯mysql,原來系統MySQL的要先用卸載.
login:root
shell> removepkg MySQL
shell> groupadd MySQL
shell> cd /app
shell> mkdir MySQL
shell> chmod 744 MySQL
shell> useradd -G mysql -s /bin/bash –p /app/mysql MySQL
shell> chown -R mysql.mysql MySQL
下載MySQL4.x.x
shell> gunzip < MySQL-VERSION.tar.gz | tar -xvf -
shell> cd MySQL-VERSION
shell> CFLAGS="-O3 -mcpu=pentium3" \
CXX=gcc \
XXFLAGS="-O3 -mcpu=pentium3 -felide-constructors" \
./configure --prefix=/app/MySQL \
--with--charset=gbk \
--with-extra-charsets="gbk gb2312 big5 utf8"\
--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表現更好!可選項目很多: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
------------------------------------------
錯誤時候
shell> make clean
再回上一步
------------------------------------------------------------
shell> make install
shell> cp support-files/my-medium.cnf /etc/my.cnf
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就算成功了.
----------------------------------------------------------------------------------------------------
在UTF8字符集的老數據庫中,創建中文支持表腳本如下.