MySQL tee out.log 从客户端工作,但在脚本中运行时出现空白 [英] MySQL tee out.log works from client, but coming up blank when run in a script

查看:71
本文介绍了MySQL tee out.log 从客户端工作,但在脚本中运行时出现空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我为 mysql> 运行以下命令时:

When I run the following for the mysql> promt:

USE database;
TEE out.log;
UPDATE...query...

结果如预期的那样在 out.log 中结束.但是,当从 CLI 运行以下命令时:

the result ends up in out.log as expected. However when running the following command from CLI:

mysql -u user -pSECRET --tee out.log database < query.sql

out.log 出现空白.我也试过

out.log comes up blank. I've also tried

mysql -u user -pSECRET database < query.sql > out.log

具有相同的结果(空白文件).我花了很长时间才弄清楚原因.我错过了什么?

with the same result (blank file). I'm having a heck of a time figuring out why. What am I missing?

推荐答案

对于遇到此问题的其他人,以下是最终对我有用的方法:

For anyone else with this issue, here's what finally worked for me:

将以下内容放入 shell 脚本中:

Put the following in a shell script:

#!/bin/bash
for file in *.sql
do
  mysql -u user -pSECRET -v database < $file
done

然后用

sh run.sh > logfile 2>&1

这会运行我所有的查询,并显示

This runs all my queries, and shows the

Query OK, xx rows affected;

或我的日志文件中出现的任何错误.希望这可以为下一个人节省几个小时.

or whatever errors come up in my logfile. Hope this saves the next guy a few hours.

这篇关于MySQL tee out.log 从客户端工作,但在脚本中运行时出现空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆