default-character-set=utf8
(有的版本不支持default-character-set=utf8,用character_set_server=utf8来取代 default-character-set=utf8即可)
注:如果没有[client]就手工加入[client]段
( 5.0以上版本修改方法:
修改/etc/my.cnf 中的设置,
在[client]节点下添加
default-character-set=utf8
在[mysqld]节点下添加
character-set-server=utf8
collation-server=utf8_general_ci
)
然后重启mysql即可
附关闭启动命令:(
[root@sg211 mysql-cluster]# bin/mysqladmin -u root -p shutdown
[root@sg211 mysql-cluster]# bin/mysqld_safe --defaults-file=/opt/mysql-cluster/etc/my.cnf --basedir=/opt/mysql-cluster --datadir=/opt/mysql-cluster/data --user=mysql &
)
这时可以验证下是否生效
mysql>show variables like 'char%'
+--------------------------+------------------------------------------+
| Variable_name | Value |
+--------------------------+------------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /opt/mysql-cluster/share/mysql/charsets/ |
+--------------------------+------------------------------------------+
8 rows in set (0.00 sec)
可以 看出都已经更正为utf8了,这样新建立的数据库缺省就是UTF8编码了。
那么已经创建好的数据库及库中的表要如何更改为utf8呢?
用alter语句(修改数据库的字符集不会改变原有数据表的字符集)
utf8:
ALTER DATABASE `数据库` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci
ALTER TABLE `数据表` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci
gbk (包含gb2312):
ALTER DATABASE `数据库` DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci
ALTER TABLE `数据表` DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci
libname mysqllib mysql user="root" password="" database="test"proc sql
create table man as select * from mysqllib.message
quit
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)