Home >Database >Mysql Tutorial >怎样把你的 MySQL完全中文化(2)_MySQL

怎样把你的 MySQL完全中文化(2)_MySQL

WBOY
WBOYOriginal
2016-06-01 13:57:081218browse

     看见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。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn