mysql服务端编码的设置
本篇内容主要讲解“MySQL服务端编码的设置”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“mysql服务端编码的设置”吧!
成都创新互联公司是专业的靖远网站建设公司,靖远接单;提供成都做网站、网站设计、外贸营销网站建设,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行靖远网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!
安装完,启动后发现服务器默认使用的是lat1编码.
具体操作和查看过程如下:
启动方式: /etc/init.d/mysql.server start
效果:
Database changed
mysql> status
--------------
mysql Ver 14.12 Distrib 5.0.77, for redhat-linux-gnu (x86_64) using readline 5.1
Connection id: 8
Current database: demodb
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.5.21 MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: latin1
Db characterset: utf8
Client characterset: latin1
Conn. characterset: latin1
UNIX socket: /var/lib/mysql/mysql.sock
Uptime: 33 sec
Threads: 7 Questions: 137 Slow queries: 0 Opens: 83 Flush tables: 1 Open tables: 76 Queries per second avg: 4.151
--------------
mysql>
启动方式: /etc/init.d/mysql.server start --character-set-server=utf8
效果:
mysql> use demodb;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> status;
--------------
mysql Ver 14.12 Distrib 5.0.77, for redhat-linux-gnu (x86_64) using readline 5.1
Connection id: 4
Current database: demodb
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.5.21 MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: utf8
Client characterset: latin1
Conn. characterset: latin1
UNIX socket: /var/lib/mysql/mysql.sock
Uptime: 1 min 15 sec
Threads: 4 Questions: 131 Slow queries: 0 Opens: 84 Flush tables: 1 Open tables: 77 Queries per second avg: 1.746
--------------
mysql>
这种方式,在每次启动的时候都需要指定编码参数.否则服务器就使用的是系统默认的lat1编码.
另外一种方法是:
mysql>set character_set_server=utf8;
这种方法我也试了,不行,再重新登录客户端后,就又恢复了原来的编码.理由很简单,系统启动的时候用的不是utf8编码.
一劳永逸的办法,就是通过修改配置文件实现.
# vim /etc/my.cnf
内容如下:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
#添加下面的红字内容
character-set-server=utf8
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
到此,相信大家对“mysql服务端编码的设置”有了更深的了解,不妨来实际操作一番吧!这里是创新互联网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
当前文章:mysql服务端编码的设置
URL网址:http://pwwzsj.com/article/pdseec.html