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

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>
主站蜘蛛池模板: 子长县| 玉环县| 湘乡市| 集安市| 东辽县| 宣武区| 古交市| 安徽省| 柳江县| 平乐县| 隆安县| 内江市| 桂平市| 平和县| 张家川| 德江县| 临沂市| 湾仔区| 四会市| 南漳县| 清河县| 当阳市| 天峻县| 松滋市| 都江堰市| 漳平市| 六盘水市| 淮阳县| 南溪县| 花莲县| 松江区| 苍溪县| 镇安县| 木兰县| 眉山市| 黎平县| 阿克| 曲阳县| 东海县| 舞钢市| 莆田市|