【发布时间】:2019-02-27 13:19:05
【问题描述】:
我很困惑我在 bash 脚本中使用以下 mysql 命令以 HTML 格式获取 SELECT 语句的地方出错了。
#!/bin/bash
dbhost="localhost"
dbname="unicentaopos"
dbuser="user"
dbpass="pass"
mysql -h $dbhost -u $dbuser -p $dbpass -H -e "SELECT NOW();" $dbname > /home/imperial/.scripts/test.txt
一切都与我的脚本相同,除了出于明显原因的凭据。我还尝试将变量硬编码到命令中 - 结果相同。
我看不出我所做的有什么问题,但是生成的文本文件只包含 mysql 使用选项:
mysql Ver 14.14 Distrib 5.7.25, for Linux (x86_64) using EditLine wrapper
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Usage: mysql [OPTIONS] [database]
-?, --help Display this help and exit.
-I, --help Synonym for -?
etc etc etc etc.....
谁能告诉我怎么了?
【问题讨论】:
-
您指定了主机吗? -h 主机名
-
对不起大家,我很困惑那个标签是怎么进来的,我复制和粘贴的时候一定是打错了东西。我的脚本确实正确使用了 $dbhost,这只是 localhost - 结果相同。
-
我们不知道你的命令在完成变量扩展后是什么。建议你使用
set -x在命令完成所有扩展后启用调试回显。 -
对不起,我离开了一段时间,但仍然需要解决这个问题!我已经编辑了我的问题以包含我的整个脚本。我尝试了
set -x,但它只是将mysql命令重复给我,前缀为+
标签: mysql ubuntu select command-line