Create and manage databases

MySQL  |  PostgreSQL  |  SQL Server

This page contains information about creating, listing, and deleting MySQLdatabases on a Cloud SQL instance.

A newly-created instance has four system databases:

  • information_schema: Provides access to database metadata, information about the MySQL server.
  • mysql: The system schema. It contains tables that store information required by the MySQL server as it runs.
  • performance_schema: A feature for monitoring MySQL Server execution at a low level.
  • sys: Contains a set of objects that helps DBAs and developers interpret data collected by the performance schema.

For more information about MySQL databases, see theMySQL documentation.

Before you begin

Before completing the tasks on this page, you must have:

If you plan to use the mysql client to create or manage your databases,you must have:

Create a database on the Cloud SQL instance

Note:The maximum length of the database name is 64 characters. For more information on other criteria for this name, seeSchema Object Names.

If you don't specify a custom character set and collation when you create your database, then the database has the following default values:

  • MySQL 5.6, 5.7: (created with Google Cloud console, Cloud SQL Admin API,gcloud CLI, Terraform, or mysql client)
    • Character set:utf8
    • Collation:utf8_general_ci
  • MySQL 8.0.x and later (created with the Google Cloud console)
    • Character set:utf8
    • Collation:utf8_general_ci
  • MySQL 8.0.x and later (created with the Cloud SQL Admin API,gcloud CLI, Terraform, or mysql client)
    • Character set:utf8mb4
    • Collation:utf8mb4_0900_ai_ci

If you need to modify the character set or collation configuration of your database after creation, then seeUpdate the character set and collation for a database.

Console

  1. In the Google Cloud console, go to theCloud SQL Instances page.

    Go to Cloud SQL Instances

  2. To open theOverview page of an instance, click the instance name.
  3. SelectDatabases from the SQL navigation menu.
  4. ClickCreate database.
  5. In theCreate a database dialog, specify the name of the database, and optionally the character set and collation.

    For more information about character sets and collations, seeCharacter Sets, Collations, Unicode.

  6. ClickCreate.

gcloud

For reference information, seegcloud sql databases create.

For more information about character sets and collations, seeCharacter Sets, Collations, Unicode.

gcloudsqldatabasescreateDATABASE_NAME\--instance=INSTANCE_NAME\[--charset=CHARSET]\[--collation=COLLATION]

Terraform

To create a database, use aTerraform resource.

resource "google_sql_database" "database" {  name     = "my-database"  instance = google_sql_database_instance.instance.name}

Apply the changes

To apply your Terraform configuration in a Google Cloud project, complete the steps in the following sections.

Prepare Cloud Shell

  1. LaunchCloud Shell.
  2. Set the default Google Cloud project where you want to apply your Terraform configurations.

    You only need to run this command once per project, and you can run it in any directory.

    export GOOGLE_CLOUD_PROJECT=PROJECT_ID

    Environment variables are overridden if you set explicit values in the Terraform configuration file.

Prepare the directory

Each Terraform configuration file must have its own directory (alsocalled aroot module).

  1. InCloud Shell, create a directory and a new file within that directory. The filename must have the.tf extension—for examplemain.tf. In this tutorial, the file is referred to asmain.tf.
    mkdirDIRECTORY && cdDIRECTORY && touch main.tf
  2. If you are following a tutorial, you can copy the sample code in each section or step.

    Copy the sample code into the newly createdmain.tf.

    Optionally, copy the code from GitHub. This is recommended when the Terraform snippet is part of an end-to-end solution.

  3. Review and modify the sample parameters to apply to your environment.
  4. Save your changes.
  5. Initialize Terraform. You only need to do this once per directory.
    terraform init

    Optionally, to use the latest Google provider version, include the-upgrade option:

    terraform init -upgrade

Apply the changes

  1. Review the configuration and verify that the resources that Terraform is going to create or update match your expectations:
    terraform plan

    Make corrections to the configuration as necessary.

  2. Apply the Terraform configuration by running the following command and enteringyes at the prompt:
    terraform apply

    Wait until Terraform displays the "Apply complete!" message.

  3. Open your Google Cloud project to view the results. In the Google Cloud console, navigate to your resources in the UI to make sure that Terraform has created or updated them.
Note: Terraform samples typically assume that the required APIs are enabled in your Google Cloud project.

Delete the changes

To delete your changes, do the following:

  1. To disable deletion protection, in your Terraform configuration file set thedeletion_protection argument tofalse.
    deletion_protection =  "false"
  2. Apply the updated Terraform configuration by running the following command and enteringyes at the prompt:
    terraform apply
  1. Remove resources previously applied with your Terraform configuration by running the following command and enteringyes at the prompt:

    terraform destroy

REST v1

The following request uses thedatabases:insert method to create a new database on the specified instance.

Before using any of the request data, make the following replacements:

  • project-id: The project ID
  • instance-id: The instance ID
  • database-name: The name of a database inside the Cloud SQL instance

HTTP method and URL:

POST https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/databases

Request JSON body:

{  "project": "project-id",  "instance": "instance-id",  "name": "database-name"}

To send your request, expand one of these options:

curl (Linux, macOS, or Cloud Shell)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login , or by usingCloud Shell, which automatically logs you into thegcloud CLI . You can check the currently active account by runninggcloud auth list.

Save the request body in a file namedrequest.json, and execute the following command:

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/databases"

PowerShell (Windows)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login . You can check the currently active account by runninggcloud auth list.

Save the request body in a file namedrequest.json, and execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/databases" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

Response

{  "kind": "sql#operation",  "targetLink": "https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id",  "status": "PENDING",  "user": "user@example.com",  "insertTime": "2020-01-21T22:43:37.981Z",  "operationType": "CREATE_DATABASE",  "name": "operation-id",  "targetId": "instance-id",  "selfLink": "https://sqladmin.googleapis.com/v1/projects/project-id/operations/operation-id",  "targetProject": "project-id"}

REST v1beta4

The following request uses thedatabases:insert method to create a new database on the specified instance.

Before using any of the request data, make the following replacements:

  • project-id: The project ID
  • instance-id: The instance ID
  • database-name: The name of a database inside the Cloud SQL instance

HTTP method and URL:

POST https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/databases

Request JSON body:

{  "project": "project-id",  "instance": "instance-id",  "name": "database-name"}

To send your request, expand one of these options:

curl (Linux, macOS, or Cloud Shell)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login , or by usingCloud Shell, which automatically logs you into thegcloud CLI . You can check the currently active account by runninggcloud auth list.

Save the request body in a file namedrequest.json, and execute the following command:

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/databases"

PowerShell (Windows)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login . You can check the currently active account by runninggcloud auth list.

Save the request body in a file namedrequest.json, and execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/databases" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

Response

{  "kind": "sql#operation",  "targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id",  "status": "PENDING",  "user": "user@example.com",  "insertTime": "2020-01-21T22:43:37.981Z",  "operationType": "CREATE_DATABASE",  "name": "operation-id",  "targetId": "instance-id",  "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/operations/operation-id",  "targetProject": "project-id"}

mysql Client

For reference information, seeCREATE DATABASE in the MySQL documentation.

For more information about character sets and collations, seeCharacter Sets, Collations, Unicode.

CREATEDATABASEdatabase_name[[CHARACTERSETcharset_name][COLLATEcollation_name]];

List your databases

To list all databases on an instance:

Console

  1. In the Google Cloud console, go to theCloud SQL Instances page.

    Go to Cloud SQL Instances

  2. To open theOverview page of an instance, click the instance name.
  3. ClickDatabases from the left side menu. TheDatabases page lists databases along with their collation type, character set, and database type.

gcloud

For reference information, seegcloud sql databases list.

gcloudsqldatabaseslist\--instance=INSTANCE_NAME

REST v1

The following request uses thedatabases:list method to list the databases for an instance.

When you list the databases using the API, you seeadditional template databases and a system database that are not displayed bythe console. You cannot delete or manage the system database.

Before using any of the request data, make the following replacements:

  • project-id: The project ID
  • instance-id: The instance ID

HTTP method and URL:

GET https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/databases

To send your request, expand one of these options:

curl (Linux, macOS, or Cloud Shell)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login , or by usingCloud Shell, which automatically logs you into thegcloud CLI . You can check the currently active account by runninggcloud auth list.

Execute the following command:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/databases"

PowerShell (Windows)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login . You can check the currently active account by runninggcloud auth list.

Execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/databases" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

Response

{  "kind": "sql#database",  "charset": "utf8",  "collation": "utf8_general_ci",  "etag": "etag",  "name": "sys",  "instance": "instance-id",  "selfLink": "https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/databases/sys",  "project": "project-id"}

Note: Thedatabases.list API supports only response payloads thatinclude up to 4 MB of text.

If you run a database list request on alarge instance, then you might receive an error. If this occurs, then to get thelist of databases, we recommend that you run the request directly from theinstance.

REST v1beta4

The following request uses thedatabases:list method to list the databases for an instance.

When you list the databases using the API, you seeadditional template databases and a system database that are not displayed bythe console. You cannot delete or manage the system database.

Before using any of the request data, make the following replacements:

  • project-id: The project ID
  • instance-id: The instance ID

HTTP method and URL:

GET https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/databases

To send your request, expand one of these options:

curl (Linux, macOS, or Cloud Shell)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login , or by usingCloud Shell, which automatically logs you into thegcloud CLI . You can check the currently active account by runninggcloud auth list.

Execute the following command:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/databases"

PowerShell (Windows)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login . You can check the currently active account by runninggcloud auth list.

Execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/databases" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

Response

{  "kind": "sql#database",  "charset": "utf8",  "collation": "utf8_general_ci",  "etag": "etag",  "name": "sys",  "instance": "instance-id",  "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/databases/sys",  "project": "project-id"}

Note: Thedatabases.list API supports only response payloads thatinclude up to 4 MB of text.

If you run a database list request on alarge instance, then you might receive an error. If this occurs, then to get thelist of databases, we recommend that you run the request directly from theinstance.

mysql Client

For reference information, seeSHOW DATABASES in the MySQL documentation.

SHOWDATABASES;

Delete a database

To delete a database on the Cloud SQL instance:

Console

  1. In the Google Cloud console, go to theCloud SQL Instances page.

    Go to Cloud SQL Instances

  2. To open theOverview page of an instance, click the instance name.
  3. ClickDatabases from the left side menu.
  4. In the database list, find the database you want to delete and click the trash can icon.
  5. In theDelete database dialog, enter the name of the database and then clickDelete.
Note: Deleting a database removes all files in the database's directory,including any files not directly used by the database. Examples of such files are#sql-* files created from interrupted ALTER TABLE operations inMySQL 5.6 and MySQL 5.7.

gcloud

For reference information, seegcloud sql databases delete.

gcloudsqldatabasesdeleteDATABASE_NAME\--instance=INSTANCE_NAME
Note: Deleting a database removes all files in the database's directory,including any files not directly used by the database. Examples of such files are#sql-* files created from interrupted ALTER TABLE operations inMySQL 5.6 and MySQL 5.7.

REST v1

The following request uses thedatabases:delete method to delete the specified database.

Before using any of the request data, make the following replacements:

  • project-id: The project ID
  • instance-id: The instance ID
  • database-name: The name of a database inside the Cloud SQL instance

HTTP method and URL:

DELETE https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/databases/database-name

To send your request, expand one of these options:

curl (Linux, macOS, or Cloud Shell)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login , or by usingCloud Shell, which automatically logs you into thegcloud CLI . You can check the currently active account by runninggcloud auth list.

Execute the following command:

curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/databases/database-name"

PowerShell (Windows)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login . You can check the currently active account by runninggcloud auth list.

Execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/databases/database-name" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

Response

{  "kind": "sql#operation",  "targetLink": "https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id",  "status": "PENDING",  "user": "user@example.com",  "insertTime": "2020-01-21T22:43:37.981Z",  "operationType": "DELETE_DATABASE",  "name": "operation-id",  "targetId": "instance-id",  "selfLink": "https://sqladmin.googleapis.com/v1/projects/project-id/operations/operation-id",  "targetProject": "project-id"}

REST v1beta4

The following request uses thedatabases:delete method to delete the specified database.

Note: Deleting a database removes all files in the database's directory, including any files not directly used by the database. Examples of such files are#sql-* files created from interrupted ALTER TABLE operations in MySQL 5.6 and MySQL 5.7.

Before using any of the request data, make the following replacements:

  • project-id: The project ID
  • instance-id: The instance ID
  • database-name: The name of a database inside the Cloud SQL instance

HTTP method and URL:

DELETE https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/databases/database-name

To send your request, expand one of these options:

curl (Linux, macOS, or Cloud Shell)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login , or by usingCloud Shell, which automatically logs you into thegcloud CLI . You can check the currently active account by runninggcloud auth list.

Execute the following command:

curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/databases/database-name"

PowerShell (Windows)

Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login . You can check the currently active account by runninggcloud auth list.

Execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/databases/database-name" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

Response

{  "kind": "sql#operation",  "targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id",  "status": "PENDING",  "user": "user@example.com",  "insertTime": "2020-01-21T22:43:37.981Z",  "operationType": "DELETE_DATABASE",  "name": "operation-id",  "targetId": "instance-id",  "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/operations/operation-id",  "targetProject": "project-id"}

mysql Client

For reference information, seeDROP DATABASE in the MySQL documentation.

DROPDATABASE[database_name];
Note: If the database's directory contains any files not directly used by the database, theDROP DATABASE command will generate errors indicating that the database directory couldn't be deleted, such as:
  • Error dropping database (can't rmdir './database_name', errno: 39)
  • Error dropping database (can't rmdir './database_name', errno: 17)
Examples of such files are#sql-* files created from interrupted ALTER TABLE operations in MySQL 5.6 and MySQL 5.7. To delete these files and complete the DROP DATABASE operation, repeat the operation using one of the other methods: the console, thegcloud command, or the REST API call.

What's next

Try it for yourself

If you're new to Google Cloud, create an account to evaluate how Cloud SQL performs in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.

Try Cloud SQL free

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-07-16 UTC.