把mysql查詢結果儲存到檔案的shell指令碼

2022-09-29 17:21:19 字數 518 閱讀 8207

該指令碼是先刪除已經存在的檔案,然後後台執行sql語句將其執行結果以一定的格式寫入檔案

複製** **如下:

#!程式設計客棧/bin/bas程式設計客棧h

if [ -f "/www.cppcns.comvar/lib/mysql/hell.txt" ]; then

rm -f /var/lib/mysql/hell.txt

echo "delete /var/lib/myscyvxuzsnroql/hell.txt" >> hell.txt

fimysql -uroot -plab select yonghuid,xueyuanid into outfile './hell.txt' fields terminawww.cppcns.comted by '|' lines terminated by '\r\n' from sns_home_user where yonghuid < 20;

eof

本文標題: 把mysql查詢結果儲存到檔案的shell指令碼

本文位址:

mysql將查詢結果儲存到檔案

1.新建查詢語句檔案query.sql,內容如下 set names utf8 select feedid,city message from feed limit 1000 上面的set names utf8語句是設施當前使用的編碼,如果編碼和資料庫的編碼不一致,會出現亂碼 2.執行如下 root...

將MySQL中sql執行結果儲存到檔案

有兩種方法。方法一 在mysql 提示符中使用tee mysql tee output.txt logging to file output.txt mysql notee outfile disabled.或者mysql t output.txt logging to file output.tx...

利用python將hive查詢結果儲存到mysql

python指令碼連線hive獲取返回值 此指令碼支援add jar file 使用者hive查詢結果的返回值更新mysql指定表指定字段 def mysqlexe sql conn mysqldb.connect host 10.10.111.111 user user passwd passwo...