0

提前感谢您的帮助!!!

我有一个在本地工作的 mySQL 语句:

mysql -u root -ppassword  -e 'SELECT "Column 1 text" as "Column 1 Heading", table1.* FROM table1;' dataBase1

如果我尝试使用 SSH 运行它,则会出错。我不知道如何通过 SSH 获取 SQL 语句中的引号。

ssh server1 "mysql -u userName -ppassword  -e 'SELECT 'Column 1 text' as 'Column 1 Heading', table1.* FROM table1;' dataBase1"

任何建议将不胜感激..

谢谢,~多纳文

4

2 回答 2

0

在结合了几个来源的反馈后,这就是我想出的。

用 echo 将 select 语句移到命令的前面,并通过管道将其传递给 ssh mysql 命令,我无需担心转义。

它似乎有效:

echo 'SELECT "server1" as "Server", table1.* FROM table1 INTO OUTFILE "/tmp/temp.csv" FIELDS ESCAPED BY """" TERMINATED BY "," ENCLOSED BY """" LINES TERMINATED BY "\r\n"' | ssh server1 mysql -u root -ppassword dataBase
于 2013-12-04T23:00:07.610 回答
0

尝试
ssh server1 "mysql -u userName -ppassword dataBase1 -e 'SELECT \"Column 1 text\" as \"Column 1 Heading\", table1.* FROM table1;' "

于 2013-11-13T21:29:04.417 回答