简体   繁体   English

如何将 sql 文件传递给 gcloud sql 导出而不是内联 sql?

[英]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 语句,从而使其难以阅读和更新。

GCloud Coud SQL Postgres:“错误:表的权限被拒绝<div id="text_translate"><p>我在 Google Cloud SQL 中有一个由用户“api”创建的 postgres 数据库。 现在我想使用我自己的用户读取该数据库上的一些数据。 我可以连接到数据库,但是当我运行时</p><pre>SELECT * FROM data;</pre><p> 我得到错误:</p><pre> ERROR: permission denied for table data</pre><hr><p> 编辑</p><p>我尝试GRANT ALL PRIVILEGES ON DATABASE website TO sev; 但这没有用。 定义数据库的 SQL 如下所示:</p><pre> CREATE DATABASE website WITH OWNER = cloudsqlsuperuser ENCODING = 'UTF8' LC_COLLATE = 'en_US.UTF8' LC_CTYPE = 'en_US.UTF8' TABLESPACE = pg_default CONNECTION LIMIT = -1; GRANT ALL ON DATABASE website TO cloudsqlsuperuser; GRANT TEMPORARY, CONNECT ON DATABASE website TO PUBLIC; GRANT ALL ON DATABASE website TO sev;</pre></div>"<table> </table> - GCloud Coud SQL Postgres: "ERROR: permission denied for table <table>"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将过滤器应用于 gcloud sql - apply filter to gcloud sql 通过/参考 Apache 中的 SQL 文件,而不是字符串 - Pass/Refer a SQL file in Apache Beam instead of string 如何在 GCloud SQL 实例上运行迁移? - How do I run migrations on GCloud SQL instance? 我如何编辑和减少 gcloud SQL 实例大小(ssd 存储) - How can i edit and reduce gcloud SQL instance size (ssd storage) GCloud Coud SQL Postgres:“错误:表的权限被拒绝<div id="text_translate"><p>我在 Google Cloud SQL 中有一个由用户“api”创建的 postgres 数据库。 现在我想使用我自己的用户读取该数据库上的一些数据。 我可以连接到数据库,但是当我运行时</p><pre>SELECT * FROM data;</pre><p> 我得到错误:</p><pre> ERROR: permission denied for table data</pre><hr><p> 编辑</p><p>我尝试GRANT ALL PRIVILEGES ON DATABASE website TO sev; 但这没有用。 定义数据库的 SQL 如下所示:</p><pre> CREATE DATABASE website WITH OWNER = cloudsqlsuperuser ENCODING = 'UTF8' LC_COLLATE = 'en_US.UTF8' LC_CTYPE = 'en_US.UTF8' TABLESPACE = pg_default CONNECTION LIMIT = -1; GRANT ALL ON DATABASE website TO cloudsqlsuperuser; GRANT TEMPORARY, CONNECT ON DATABASE website TO PUBLIC; GRANT ALL ON DATABASE website TO sev;</pre></div>"<table> </table> - GCloud Coud SQL Postgres: "ERROR: permission denied for table <table>" 用于 SQL 实例 GCP 的 gcloud iam service-accounts list 命令 - gcloud iam service-accounts list command for SQL instance GCP (GCloud SQL) 有没有办法通过 CLI 或 API 选择加入维护通知? - (GCloud SQL) Is there a way to opting in to maintenance notifications via CLI or API? 如何导出 Google Storage 中 Cloud SQL 数据库的备份? - How to export backup of Cloud SQL database in Google Storage? ERROR: (gcloud.sql.instances.describe) HTTPError 404: Cloud SQL 实例不存在,但确实存在? - ERROR: (gcloud.sql.instances.describe) HTTPError 404: The Cloud SQL instance does not exist, but it does exist? Databricks 的凭据传递 Sql - Credential pass through for Databricks Sql
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM