This page contains information about creating, listing, and deleting MySQL databases on a Cloud SQL instance.
For more information about MySQL databases, see the MySQL documentation.Before you begin
Before completing the tasks on this page, you must have:
- Created a Cloud SQL instance. For more information, see Creating instances.
If you plan to use the mysql client to create or manage your databases, you must have:
- Configured access and connected to the instance with a
mysql
client. For more information about connection options, see Connection Options for External Applications.
Creating a database
Follow the rules in Schema Object Names when you create your database name. If not set on creation, new databases have the following default values:- Character set:
utf8
- Collation:
utf8_general_ci
To create a database on the Cloud SQL instance:
Console
- Go to the Cloud SQL Instances page in the Google Cloud Console.
- Select the instance you want to add the database to.
- Select the DATABASES tab.
- Click Create database.
- In the Create a database dialog, specify the
name of the database, and optionally the character set and collation.
For more information about character sets and collations, see Character Sets, Collations, Unicode.
- Click Create.
gcloud
For reference information, see gcloud sql databases create.For more information about character sets and collations, see Character Sets, Collations, Unicode.
gcloud sql databases create [DATABASE_NAME] --instance=[INSTANCE_NAME] [--charset=CHARSET] [--collation=COLLATION]
cURL
The following request uses the databases:insert method to create a new database on the specified instance.
gcloud auth login ACCESS_TOKEN="$(gcloud auth print-access-token)" curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \ --header 'Content-Type: application/json' \ --data '{"project": "[PROJECT-ID]", "instance": "[INSTANCE_NAME]", "name": "[DATABASE_NAME]"}' \ -X POST \ https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances/[INSTANCE_NAME]/databases
MySQL Client
For reference information, see CREATE DATABASE in the MySQL documentation.
For more information about character sets and collations, see Character Sets, Collations, Unicode.
CREATE DATABASE [database_name] [[CHARACTER SET charset_name][COLLATE collation_name]];
Listing your databases
To list all databases on an instance:
Console
- Go to the Cloud SQL Instances page in the Google Cloud Console.
- Select the instance for which you want to list databases.
- Click DATABASES.
For a newly-created instance, you should see three system databases:
information_schema
,mysql
, andperformance_schema
.
gcloud
For reference information, see gcloud sql databases list.
gcloud sql databases list --instance=[INSTANCE_NAME]
cURL
The following request uses the databases:list method to list the databases for an instance.
When you list the databases using the API, you see additional template databases and a system database that are not displayed by the console. You cannot delete or manage the system database.
gcloud auth login ACCESS_TOKEN="$(gcloud auth print-access-token)" curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \ -X GET \ https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances/[INSTANCE_NAME]/databases
MySQL Client
For reference information, see SHOW DATABASES in the MySQL documentation.
SHOW DATABASES;
Deleting a database
To delete a database on the Cloud SQL instance:
Console
- Go to the Cloud SQL Instances page in the Google Cloud Console.
- Select the instance that contains the database you want to delete.
- Click DATABASES.
- In the database list, find the database you want to delete and click the trash can icon.
- In the Delete database dialog box, click OK.
gcloud
For reference information, see gcloud sql databases delete.
gcloud sql databases delete [DATABASE_NAME] --instance=[INSTANCE_NAME]
cURL
The following request uses the databases:delete method to delete the specified database.
gcloud auth login ACCESS_TOKEN="$(gcloud auth print-access-token)" curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \ -X DELETE \ https://www.googleapis.com/sql/v1beta4/projects/[PROJECT-ID]/instances/[INSTANCE_NAME]/databases/[DATABASE_NAME]
MySQL Client
For reference information, see DROP DATABASE in the MySQL documentation.
DROP DATABASE [database_name];
What's next
- Manage users for your instance.
- Import data into your instance.
- Learn about options for connecting to your instance using the mysql client.
- Create a database table.