您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

解析MySQL完全中文化_MySQL

2024/3/1 18:06:52发布30次查看
由于系统自带的mysql默认字符集不是gbk,因此给数据库的推广应用以及中文程序的开发带来极大的不便,在没完没了的gbk和utf8的转换过程中消耗了我们无数的精力以及系统的资源。
先将slack支持中文,然后重新编译mysql,原来系统mysql的要先卸载:
login:rootshell> removepkg mysqlshell> groupadd mysqlshell> cd /appshell> mkdir mysqlshell> chmod 744 mysqlshell> useradd -g mysql -s /bin/bash –p /app/mysql mysqlshell> chown -r mysql.mysql mysql
再下载mysql4.x.x:
shell> gunzip cd mysql-versionshell> 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类型优化编译,可以让你的mysql表现更好。可选项目很多: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 installshell> cp support-files/my-medium.cnf /etc/my.cnfshell> cd /app/mysqlshell> bin/mysql_install_db --user=rootshell> chown -r root .shell> chown -r mysql varshell> 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 -pmysql> status...server characterset: gbkdb characterset: gbkclient characterset: gbkconn. 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 -pmysql>use testmysql> 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
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product