快捷搜索:  as  test  1111  test aNd 8=8  test++aNd+8=8  as++aNd+8=8  as aNd 8=8

ag亚洲游只为非凡:让MYSQL彻底支持中文(slack10.1版)MYSQL



提纲:系统自带的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> gunzipcd 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-assembleag亚洲游只为非凡r \

--withag亚洲游只为非凡-client-ldflags=-all-static \

--with-mysqld-ldflags=-all-static

//-mcpu 根据CPU类型优化编译,可以让你的mysq体现更好!可选项ag亚洲游只为非凡目很多: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 --uag亚洲游只为非凡ser=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 characterseag亚洲游只为非凡t: gbk

Client characterset: gbk

Conn. characterset: gbk

....

望见characterset全是gbk就算成功了.

----------------------------------------------------------------------------------------------------

在UTF8字符集的老数据库中,创建中文支持表脚本如下,对字段加上字符集阐明

CREATE TABLE `test`.`cn` (

`zh` CHAR(10) CHARACTER SET gb2312 COLLATE gb2312_chinese_ci NOT NULL,

`中文` INT(11) NOT NULL

)

ENGINE = MYISAM;

注:CHARACTER SET 写GB2312 和gbk都可以,gbk优于gb2312.

对付新创建的数据库加个默认字符集声明GBK,就不用建表时刻每个字段声清楚明了,这样看起来简单流通,没有特殊的痕迹,建议多采纳这种措施.

mysql> CREATE DATABASE dbCN DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci;

CREATE TABLE `dbCN`.`cn` (

`zh` CHAR(10) NOT NULL,

`中文` INT(11) NOT NULL

)

ENGINE = MYISAM;

mysql> insert into cn values("真的?",1);

注:假如这些脚本用bin/mysql敕令行是输入不了,可以 用mysql query Browser,或者编程履行.

--------------------------------------------------------------------------------------------------------

shell> bin/mysql -u root --default-character-set=gbk -p

mysql>use test

mysql> select * from cn;

+--------+------+

| zh | 中文 |

+--------+------+

| 真的?| 1 |

+--------+------+

1 row in set (0.00 sec)

---------------------------------------------

着末改动启动文件/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

免责声明:以上内容源自网络,版权归原作者所有,如有侵犯您的原创版权请告知,我们将尽快删除相关内容。

您可能还会对下面的文章感兴趣: