1. 程式人生 > >linux-記錄mysql中文亂碼問題

linux-記錄mysql中文亂碼問題

差點被中文搞崩了,寫了一個程序,評論功能,結果中文根本無法識別,記錄一下中文亂碼的問題

檢視預設字符集 
#mysql -u root - p 
#(輸入密碼) 

mysql> show variables like 'character_set%';

可以看到你的編碼..我全是utf-8結果還是亂碼了.

結果還是會導致中文亂碼,

最後發現,其實是需要去修改 /etc/my.cnf的配置檔案才可以

在mysqld上面加入[client]標籤.插入character-set-server=utf8 而不是 default-character-set=utf8 

在mysqld標籤中插入character-set-server=utf8 而不是 default-character-set=utf8 
否則會報:Starting MySQL...The server quit without updating PID file [失敗]lib/mysql/localhost.localdomain.pid).異常

最後在插入[mysql]default-character-set=utf8

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[client]
character-set-server=utf8

[mysqld]
character-set-server=utf8
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysql]
default-character-set=utf8

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
default-character-set=utf8

 重新啟動mysql伺服器

一、啟動方式
1、使用 service 啟動:service mysqld start
2、使用 mysqld 指令碼啟動:/etc/inint.d/mysqld start
3、使用 safe_mysqld 啟動:safe_mysqld&
 
二、停止
1、使用 service 啟動:service mysqld stop
2、使用 mysqld 指令碼啟動:/etc/inint.d/mysqld stop
3、 mysqladmin shutdown 
 
三、重啟
1、 使用 service 啟動:service mysqld restart

完成