close

一般人在使用mysql伺服器時常會被phpMyadmin 誤導,其實修改phpMyadmin中的語系與mysql毫無相關,底下是觀看伺服器中mysql語系的正確方式:

#mysql -u root -p
Enter password:(打上mysql的密碼)
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12 to server version: 5.0.27

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> \s  <--就是這個指令
--------------
mysql  Ver 14.12 Distrib 5.0.27, for redhat-linux-gnu (i686) using readline 5.0

Connection id:          12
Current database:
Current user:           root@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server version:         5.0.27
Protocol version:       10
Connection:             Localhost via UNIX socket
(重點在底下幾行:)
Server characterset:    utf8
Db     characterset:    utf8
Client characterset:    utf8
Conn.  characterset:    utf8

UNIX socket:            /var/lib/mysql/mysql.sock
Uptime:                 4 hours 44 min 38 sec                                       

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


由上可知,要將mysql調整成全UTF8有四項參數需要調整。如果上述四項是Latin1(為何叫Latin1?因為mysql是瑞典人開發的,他們用的語系叫Latin1,所以mysql預設語系就是Latin1),該如何調整成utf8?進入mysql的設定檔作修正即可。

步驟一:先將mysql之原設定檔作備份。
#mv /etc/my.cnf   /etc/my.cnf.bak
步驟二:設定一個新的mysql 之設定檔。
#vim /etc/my.cnf
步驟三:將底下之指令copy到設定檔中。

[client]
default-character-set=utf8
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
default-character-set=utf8
default-collation=utf8_general_ci
#default-character-set=big5
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1

[mysql.server]
user=mysql
basedir=/var/lib

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid 
步驟四:重啟mysql。
#service mysqld restart
                  

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

這時mysql已全部修改成utf8了。但最後還需要php程式碼之修正。一般來說,程式開發者都會將其設定寫在config.inc.php這支程式中(寫php資料庫時通常會加入AdoDB套件,故底下使用Adodb語法)。

<?php

....................

$DB->Execute("set names 'utf8';");<----也就是保證程式中用utf8在傳送。

................................
?>

 

 

 

 

 

 

 

 

如此一來,所有環境就會修改成utf8而不會出現亂碼了。^.^

arrow
arrow
    全站熱搜

    bunkera 發表在 痞客邦 留言(3) 人氣()