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

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>
主站蜘蛛池模板: 丰镇市| 金乡县| 任丘市| 桦南县| 翁牛特旗| 台东县| 堆龙德庆县| 全州县| 额尔古纳市| 兰州市| 桐乡市| 宾川县| 文登市| 元谋县| 九江市| 乡宁县| 杭锦后旗| 安西县| 阳朔县| 虎林市| 祁连县| 天长市| 河西区| 南陵县| 宣威市| 沧州市| 神农架林区| 兴和县| 靖安县| 米易县| 梅州市| 台中市| 金坛市| 京山县| 达州市| 莎车县| 阿合奇县| 宁化县| 兰溪市| 历史| 柞水县|