您好,登錄后才能下訂單哦!
本篇內(nèi)容主要講解“mysql服務(wù)端編碼的設(shè)置”,感興趣的朋友不妨來看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“mysql服務(wù)端編碼的設(shè)置”吧!
安裝完,啟動(dòng)后發(fā)現(xiàn)服務(wù)器默認(rèn)使用的是lat1編碼.
具體操作和查看過程如下:
啟動(dòng)方式: /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>
啟動(dòng)方式: /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>
這種方式,在每次啟動(dòng)的時(shí)候都需要指定編碼參數(shù).否則服務(wù)器就使用的是系統(tǒng)默認(rèn)的lat1編碼.
另外一種方法是:
mysql>set character_set_server=utf8;
這種方法我也試了,不行,再重新登錄客戶端后,就又恢復(fù)了原來的編碼.理由很簡(jiǎn)單,系統(tǒng)啟動(dòng)的時(shí)候用的不是utf8編碼.
一勞永逸的辦法,就是通過修改配置文件實(shí)現(xiàn).
# vim /etc/my.cnf
內(nèi)容如下:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
#添加下面的紅字內(nèi)容
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
到此,相信大家對(duì)“mysql服務(wù)端編碼的設(shè)置”有了更深的了解,不妨來實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。