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

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>
主站蜘蛛池模板: 高碑店市| 封丘县| 新邵县| 谷城县| 鄂尔多斯市| 庄河市| 民乐县| 襄垣县| 衡阳市| 基隆市| 晋州市| 利辛县| 南康市| 上杭县| 文昌市| 尉犁县| 洛隆县| 闸北区| 罗田县| 常德市| 剑川县| 西和县| 南木林县| 博白县| 弋阳县| 利川市| 呼和浩特市| 隆安县| 金溪县| 运城市| 和田县| 桑日县| 卢龙县| 南宁市| 禄劝| 凤冈县| 茶陵县| 隆尧县| 株洲县| 丹凤县| 乾安县|