From charlesreid1

Revision as of 00:38, 12 September 2017 by Admin (talk | contribs)

To set up MySQL on Google Cloud, create a new project using the Google Cloud Platform Console.

Link to google cloud platform console: https://console.cloud.google.com/project

Setting up Google Cloud SDK

This uses the gcloud command line tool (see Google Cloud/Gcloud). This tool uses the Compute Engine API, so you have to enable that first. Also, need to install Google Cloud SDK (which installs the gcloud tool). There are also client libraries that allow you to write scripts in various languages.

Link to enabling compute engine API: https://console.cloud.google.com/flows/enableapi?apiid=compute_component

Link to google cloud sdk: https://cloud.google.com/sdk/docs/

Create MySQL Compute Instance

Start by setting up project:

$ gcloud config set project project-name

Set up compute zone:

$ gcloud config set compute//zone the-zone

Now to set up a MySQL server, create a compute instance. This sets up a plain, empty Debian VM that you can SSH to and install MySQL onto. Other operating systems are available too.

Create the instance:

$ gcloud instances create dummy

SSH to the instance:

$ gcloud compute ssh dummy

Install MySQL on the compute instance:

$ sudo apt-get update
$ sudo apt-get -y install mysql-server

When you run the installation process, you will be prompted to set a root password.

(I suppose you could also use a Docker or Kubernetes image and run that in the cloud - but not sure exactly how that process would mesh with Google Cloud.)

Secure the installation using the MySQL command mysql_secure_installation:

$ sudo mysql_secure_installation

Connect to the server:

$ mysql --user=root --password

To do a "hello world" with MySQL, run the commands:

mysql> show processlist;

mysql> SELECT User, Host, Password FROM mysql.user;


Connect to MySQL Compute Instance

Once you've created the MySQL compute instance, you have a MySQL server running, and you can connect to the server using MySQL clients.

Using the web console, you can get a shell on the cloud instance using the little cloud shell icon. Alternatively, connect to a MySQL server from a MySQL client...

Link to Cloud SQL for MySQL that mentions this: https://cloud.google.com/sql/docs/mysql/quickstart

Delete MySQL Compute Instance

Once you're finished with the MySQL server you'll want to delete the VM that was allocated. I am unable to find a way to do this using the gcloud interface.

$ gcloud compute instances delete dummy --zone the-zone

Link to gcloud documentation that mentions this command: https://cloud.google.com/compute/docs/gcloud-compute/