官术网_书友最值得收藏!

Exporting Cloud SQL databases and tables

To export the Cloud SQL database to an SQL file or export the data from a table to a CSV, we can use the following command. Use the help option to learn about this command:

gcloud help sql instances export

The export option will export the file and store it in the Google Cloud Storage bucket or folder within the bucket. Before exporting the Google Cloud Storage bucket to which the file is to be saved, it should be granted a write permission for the Cloud SQL service account. Navigate to the Cloud SQL instance from which you want to export the data, as shown in the following screenshot. Copy the value of the service account:

Navigate to the Google Cloud Storage screen, click on the options button for a bucket, and choose Edit bucket permission. A panel to enter the permission details will be displayed, as shown in the screenshot. Enter the service account in the Add members textbox and in the Select a role dropdown choose Storage | Storage Object Creator. Click the Add button:

Run the following command to export the database from Cloud SQL instance to SQL file. The exported file will be stored in a GCS bucket to which we granted the permission previously:

gcloud sql instances export <instance name> gs://<bucketname>/<sql filename> --database=<database name>

To export the SQL for only one table in the database, use the --table option as shown in the following code. This will create an SQL file with drop and create option, and an insert command for all records in the table:

 gcloud sql instances export <instance name> gs://<bucketname>/<sql filename> --database=<database name> --table=<table name>
主站蜘蛛池模板: 虎林市| 张家港市| 美姑县| 永城市| 苏尼特右旗| 胶南市| 香河县| 德安县| 巢湖市| 孟津县| 额济纳旗| 家居| 涿州市| 新竹县| 宿松县| 贵定县| 土默特右旗| 海兴县| 霞浦县| 潍坊市| 即墨市| 禹城市| 祁门县| 绥阳县| 孝昌县| 全州县| 微山县| 宜阳县| 弋阳县| 宁都县| 清远市| 剑川县| 类乌齐县| 阿勒泰市| 威宁| 亚东县| 石棉县| 彭泽县| 保定市| 丹江口市| 丹阳市|