[英]How to pass a sql file to gcloud sql export instead of inline sql?
I can export my data using我可以使用导出我的数据
gcloud sql export csv .... --query='SELECT * FROM mytable'
My SELECT sql command is long and I'd like to pass it to gcloud in a file.我的 SELECT sql 命令很长,我想在文件中将它传递给 gcloud。 I couldn't find anything in the docs about that.
我在文档中找不到任何关于此的内容。 Is this possible to pass a file?
这可以传递文件吗?
https://cloud.google.com/sql/docs/mysql/import-export/import-export-csv#gcloud https://cloud.google.com/sql/docs/mysql/import-export/import-export-csv#gcloud
Try to use:尝试使用:
gcloud sql export csv .... --query=$(< x.sql)
where x.sql is the file with the SELECT statement.其中 x.sql 是带有 SELECT 语句的文件。
using options shown here: https://unix.stackexchange.com/questions/393351/pass-contents-of-file-as-argument-to-bash-script使用此处显示的选项: https://unix.stackexchange.com/questions/393351/pass-contents-of-file-as-argument-to-bash-script
This worked:这有效:
--query="$(<myFile.sql)"
--query="$(<myFile.sql)"
The answer @Piotr W. provided was just missing quotations. @Piotr W. 提供的答案只是缺少引用。
Worth noting this method allowed me to put my SELECT statement with line breaks in a file vs providing the SELECT statement inline that could not have line breaks, making it hard to read and update.值得注意的是,这种方法允许我将带有换行符的 SELECT 语句放入文件中,而不是提供不能有换行符的内联 SELECT 语句,从而使其难以阅读和更新。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.