Hide
Cloud SQL

Creating Databases

After creating an instance, you are ready to create a database on the instance. Note that you must set the root password before you can connect to the instance from applications other than Google App Engine. For more information, see creating users.

To create a database:

Developers Console

  1. Go to the Google Developers Console and select a project by clicking on the project name.
  2. In the sidebar on the left, click Storage > Cloud SQL to show a list of Cloud SQL instances for the project.
  3. Select the instance to which you want to add a database.
  4. Click Databases.
  5. Click New database.
  6. In the New MySQL Database dialog, specify the name of the database, and optionally the character set and collation.
  7. Click Add.

cURL

You can use the Cloud SQL Admin API directly to create databases. For example, using cURL, the following request uses the insert method to create a database on an instance with character set utf8 and collation utf8_general_ci.

curl --header 'Authorization: Bearer accessToken' \
     --header 'Content-Type: application/json' \
     https://www.googleapis.com/sql/v1beta4/projects/your-project-id/instances/your-instance-name/databases \
     --data '{"name": "database-name", "charset": "utf8", "collation": "utf8_general_ci"}' \
     -X POST

You can get an authorization access token to use in the cURL command from the OAuth 2.0 Playground.

SQL

  1. If you haven't already, create a user that you will connect as.
  2. Allow access to the instance by configuring access control for IP connections.
  3. From an application or tool, connect to the instance and create a database.

    For example, you can connect from MySQL client and create a database with the following commands.

    shell> mysql --host=INSTANCE_IP --user=USER_NAME --password
    mysql> create database DATABASE_NAME
    

To list databases:

Developers Console

  1. Go to the Google Developers Console and select a project by clicking on the project name.
  2. In the sidebar on the left, click Storage > Cloud SQL to show a list of Cloud SQL instances for the project.
  3. Select the instance to which you want to list databases.
  4. Click Databases.

    The databases for the instances are listed. For example, for a newly created instance (no databases added), you should see three databases: information_schema, mysql, and performance_schema.

cURL

You can use the Cloud SQL Admin API directly to list databases. For example, using cURL, the following request uses the list method to list list the databases on an instance.

curl --header 'Authorization: Bearer accessToken' \
     https://www.googleapis.com/sql/v1beta4/projects/your-project-id/instances/your-instance-name/databases \
     -X GET

You can get an authorization access token to use in the cURL command from the OAuth 2.0 Playground.

SQL

  1. If you haven't already, create a user that you will connect as.
  2. Allow access to the instance by configuring access control for IP connections.
  3. From an application or tool, connect to the instance and list the databases.

    For example, you can connect from MySQL client and list the databases with the following commands.

    shell> mysql --host=INSTANCE_IP --user=USER_NAME --password
    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | performance_schema |
    +--------------------+
    

To delete a database:

Developers Console

  1. Go to the Google Developers Console and select a project by clicking on the project name.
  2. In the sidebar on the left, click Storage > Cloud SQL to show a list of Cloud SQL instances for the project.
  3. Select the instance that contains the database you want to delete.
  4. Click Databases.
  5. In the database list, find the database you want to delete and click delete Delete..
  6. In the Delete database dialog box, click OK.

cURL

You can use the Cloud SQL Admin API directly to delete databases. For example, using cURL, the following request uses the delete method to delete a database on an instance.

curl --header 'Authorization: Bearer accessToken' \
     https://www.googleapis.com/sql/v1beta4/projects/your-project-id/instances/your-instance-name/databases/database-name \
     -X DELETE

You can get an authorization access token to use in the cURL command from the OAuth 2.0 Playground.

SQL

  1. If you haven't already, create a user that you will connect as.
  2. Allow access to the instance by configuring access control for IP connections.
  3. From an application or tool, connect to the instance and delete the database.

    For example, you can connect from MySQL client and create a database with the following commands.

    shell> mysql --host=INSTANCE_IP --user=USER_NAME --password
    mysql> drop database DATABASE_NAME