共計 1511 個字符,預計需要花費 4 分鐘才能閱讀完成。
這篇文章主要講解了“MySQL binlog 日志亂碼的處理方法”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著丸趣 TV 小編的思路慢慢深入,一起來研究和學習“MySQL binlog 日志亂碼的處理方法”吧!
OS:Red Hat Enterprise Linux Server release 6.5 (Santiago)
DB:5.6.30-log
使用 mysqlbinlog 打開日志,發現日志內容存在亂碼
首先想到檢查 MySQL 數據庫的字符集。
發現字符集都一致的,看了操作系統環境變量的字符集,發現字符集都是一直的。
[root@mysql1 log]# echo $LANG
en_US.UTF-8
接著在網上查資料發現有人說
當 mysql 服務器版本是 5.6 時,一定切記要使用版本 =3.4 的 mysqlbinlog,否則會出現亂碼問題。
查了我的 mysqlbinlog 版本:
[root@mysql1 log]# mysqlbinlog –version
mysqlbinlog Ver 3.3 for redhat-linux-gnu at x86_64
發現版本確實低于 3.4。
那這個怎么單獨升級呢???難道 MySQL 5.6.30 自帶的版本自己不能用???
使用絕對路徑再查詢一次版本:
[root@mysql1 log]# /mysql/bin/mysqlbinlog –version
/mysql/bin/mysqlbinlog Ver 3.4 for Linux at x86_64
坑爹啊!!!!絕對路徑是對的。
使用絕對路徑的方式查看日志,亂碼消失。
解決相對路徑問題。
檢查環境變量.bash_profile 的設置。
[root@mysql1 ~]# vi .bash_profile
# .bash_profile
# Get the aliases and functions
if [-f ~/.bashrc]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/mysql/bin
export PATH
加環境變量的時候把 /mysql/bin 加在的最后面,系統讀變量從前到后的順序。
檢查 /usr/bin 目錄,果然有個 mysqlbinlog 的程序,查詢版本是 3.3 的
[root@mysql1 bin]# /usr/bin/mysqlbinlog –version
/usr/bin/mysqlbinlog Ver 3.3 for redhat-linux-gnu at x86_64
現在知道問題的原因,處理方法有兩種:
1、修改.bash_profile,把 /mysql/bin 設置放在第一位,重新加載變量。
[root@mysql1 ~]# vi .bash_profile
# .bash_profile
# Get the aliases and functions
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=/mysql/bin:$PATH:$HOME/bin
export PATH
2、刪除 /usr/bin 目錄下的 mysqlbinlog 程序,可以使用改名的方式。然后重新加載變量。
[root@mysql1 bin]# mv mysqlbinlog mysqlbinlog.bak
感謝各位的閱讀,以上就是“MySQL binlog 日志亂碼的處理方法”的內容了,經過本文的學習后,相信大家對 MySQL binlog 日志亂碼的處理方法這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是丸趣 TV,丸趣 TV 小編將為大家推送更多相關知識點的文章,歡迎關注!