Forum

Cloud SQL 'Hello Wo...
 
Notifications
Clear all
2 Posts
1 Users
0 Likes
3,812 Views
Posts: 108
Topic starter
(@taichi)
Member
Joined: 4 years ago

Overview

In this tutorial, you will:

  1. Instantiate a new MySQL instance

  2. Set up and query a database

  3. Clean up the instance

 

 

10 minutes

Project setup

Google Cloud Platform resources are organised into projects. Cloud SQL needs a project to get started.

 Select a project, or 

Create SQL instance

You can create a MySQL instance using the UI.

  1. Navigate to the SQL Instances page

    SQL

     

  2. Click on 

  3. Choose a database engine:

    Verify  is selected and click the  button.

  4. Choose a MySQL instance type:

    Click 

  5. Configure instance:

    The default configuration should be sufficient. Remember these values, you'll reference them later:

    •  or choose 

  6. Click 

 

Connect to the SQL instance

The gcloud CLI is used to interface with the instance. This tool comes pre-installed in the web console shell.

Open Cloud Shell by clicking the   button in the navigation bar in the upper-right corner of the console.

Use this command to connect to the instance:

gcloud sql connect InstanceIdHere \ --user=root
 
You should see a prompt similar to the following:
MySQL [(none)]
 

Using the SQL instance

Within theMySQLprompt, run the following:

  1. Create database and table

    sql CREATE DATABASE geography; USE geography; CREATE TABLE cities (city VARCHAR(255), country VARCHAR(255));

  2. Insert data

    sql INSERT INTO cities (city, country) values ("San Francisco", "USA"); INSERT INTO cities (city, country) values ("Beijing", "China");

  3. Query

    sql SELECT * FROM cities;

    You should see the following query results:

    SELECT * FROM cities; +---------------+---------+ +---------------+---------+ +---------------+---------+
     

Cleanup

You'll need to clean up the newly created resources.

  1. Navigate to the SQL instances page.

    SQL
  2. Click on the  link to go to the details page.

  3. Click 

 

 
1 Reply
Posts: 108
Topic starter
(@taichi)
Member
Joined: 4 years ago
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> sql CREATE DATABASE geography; USE geography; CREATE TABLE cities (city VARCHAR(255), country VARCHAR(255));
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'sql CREATE DATABASE geography' at line 1
ERROR 1049 (42000): Unknown database 'geography'
ERROR 1046 (3D000): No database selected
mysql>  CREATE DATABASE geography; USE geography; CREATE TABLE cities (city VARCHAR(255), country VARCHAR(255));
Query OK, 1 row affected (0.03 sec)

Database changed
Query OK, 0 rows affected (0.05 sec)

mysql> INSERT INTO cities (city, country) values ("San Francisco", "USA"); INSERT INTO cities (city, country) values ("Beijing", "China");
Query OK, 1 row affected (0.04 sec)

Query OK, 1 row affected (0.04 sec)

mysql> SELECT * FROM cities;
+---------------+---------+
| city          | country |
+---------------+---------+
| San Francisco | USA     |
| Beijing       | China   |
+---------------+---------+
2 rows in set (0.03 sec)

mysql>
mysql>  CREATE DATABASE geography; USE geography; CREATE TABLE cities (city VARCHAR(255), country VARCHAR(255));
Query OK, 1 row affected (0.03 sec)

Database changed
Query OK, 0 rows affected (0.05 sec)

mysql> INSERT INTO cities (city, country) values ("San Francisco", "USA"); INSERT INTO cities (city, country) values ("Beijing", "China");
Query OK, 1 row affected (0.04 sec)

Query OK, 1 row affected (0.04 sec)

mysql> SELECT * FROM cities;
+---------------+---------+
| city          | country |
+---------------+---------+
| San Francisco | USA     |
| Beijing       | China   |
+---------------+---------+
2 rows in set (0.03 sec)

mysql>


Reply
Share: