您的位置:極速下載站→ 資訊首頁(yè) → 系統(tǒng)教程 → 系統(tǒng)資訊 → Linux cron執(zhí)行mysql失。ň幋a問(wèn)題)教程
時(shí)間:2019-09-16 14:31:17 作者:無(wú)名 瀏覽量:28
大家好,小編是個(gè)電腦軟件控,在接入一個(gè)途徑的時(shí)分,由于對(duì)方不給ROOT權(quán)限,也沒(méi)有MYSQL的最高權(quán)限,MYSQL的裝備這些現(xiàn)已不受掌控.所以呈現(xiàn)了一下問(wèn)題.
Linux cron執(zhí)行mysql失。ň幋a問(wèn)題)教程圖1
1.首要,為了計(jì)算服務(wù)器均勻在線人數(shù),所以寫了個(gè)SHELL腳本,每天7點(diǎn)-0點(diǎn)之間每小時(shí)履行該指令,取得當(dāng)時(shí)在線用戶,以便計(jì)算最高在線用戶,以及均勻在線用戶.
SHELL腳本如下:
time08_23.sh
------------------------------------------------------------------------------------------------------------------------------------
#!/bin/bash
# crontab -e 57 7-22 * * * /home/nemo/crontab/time08_23.bash
DB_USER=\"root\"
DB_PASS=\"***\"
DB_HOST=\"localhost\"
DB_PORT=\"3306\"
# Others vars
BIN_DIR=\"/usr/bin\"
# TODO
# 取得8080端口
THETIME=`netstat -ant / grep 8080 / wc -l`
# 取得當(dāng)時(shí)小時(shí)
THEHOUR=`date +%H`
# 更新當(dāng)時(shí)小時(shí)的現(xiàn)在人數(shù)
$BIN_DIR/mysql -u$DB_USER -p$DB_PASS -h$DB_HOST -P$DB_PORT << EOF
use wapgame4sky2;
UPDATE MgrSky SET time$THEHOUR = $THETIME WHERE TO_DAYS(date) = TO_DAYS(now());
EOF
------------------------------------------------------------------------------------------------------------------------------------
Linux cron執(zhí)行mysql失敗(編碼問(wèn)題)教程圖2
2.以上的SHELL腳本,在本地以及遠(yuǎn)程服務(wù)器上,通過(guò) source time08_23.sh 以及 ./time08_23.sh 都能正確運(yùn)轉(zhuǎn),數(shù)據(jù)無(wú)誤,一切正常
3.但以上腳本運(yùn)用cron使命調(diào)度器履行數(shù)據(jù)庫(kù)卻沒(méi)有數(shù)據(jù),這樣我一度認(rèn)為是使命調(diào)度器裝備過(guò)錯(cuò),或許權(quán)限問(wèn)題,但查詢過(guò)錯(cuò)日志取得以下信息:
Character set \'ascii\' is not a compiled character set and is not specified in the \'/usr/local/share/mysql/charsets/Index.xml\'
4.剖析一下便清楚是編碼格局的問(wèn)題.所以逐步查詢問(wèn)題所在.
4.1檢查當(dāng)時(shí)mysql編碼集設(shè)置:
然后,在shell中參加:
set names latin1;
修正腳本文件編碼格局;
修正linux體系默認(rèn)編碼集;
等等等等計(jì)劃都測(cè)驗(yàn)過(guò)了,都失利,cron履行該腳本任然報(bào)該過(guò)錯(cuò).
相同的腳本文件.為什么source 和 ./都履行正常,運(yùn)用cron履行卻呈現(xiàn)編碼問(wèn)題???這個(gè)問(wèn)題,我問(wèn)了2個(gè)linux群,居然沒(méi)有一個(gè)人能幫忙解決(或許他們底子就不愿意答理這樣的小問(wèn)題)
show variables like \'%char%\';
+--------------------------+----------------------------+
/ Variable_name / Value /
+--------------------------+----------------------------+
/ character_set_client / utf8 /
/ character_set_connection / utf8 /
/ character_set_database / utf8 /
/ character_set_filesystem / binary /
/ character_set_results / utf8 /
/ character_set_server / latin1 /
/ character_set_system / utf8 /
/ character_sets_dir / /opt/mysql/share/charsets/ /
+--------------------------+----------------------------+
檢查本地mysql編碼集設(shè)置: