程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MySQL綜合教程 >> mysql服務端編碼設置

mysql服務端編碼設置

編輯:MySQL綜合教程

安裝完mysql,啟動後發現服務器默認使用的是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
 
 
 
|----------------------------------------------------------------------------------------|
                           版權聲明  版權所有@zhyiwww

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved