From charlesreid1

 
(9 intermediate revisions by the same user not shown)
Line 12: Line 12:


==Create MySQL Compute Instance==
==Create MySQL Compute Instance==
===Manually Allocate Instance and Install MySQL===


Start by setting up project:
Start by setting up project:
Line 22: Line 24:


<pre>
<pre>
$ gcloud config set compute//zone the-zone
$ gcloud config set compute --zone us-west1
</pre>
</pre>


Line 47: Line 49:


When you run the installation process, you will be prompted to set a root password.
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 <code>mysql_secure_installation</code>:
Secure the installation using the MySQL command <code>mysql_secure_installation</code>:
Line 70: Line 70:
</pre>
</pre>


===Use Container===


==Managing MySQL Compute Instance==
The other option here, which I suppose would bypass all of the Cloud SQL stuff, is to just use a Docker container and set up the SQL server yourself. This would use the Container Engine product instead.


The gcloud command line tool can be used to manage yer cloud SQL databases.
Link to info about container engine: https://cloud.google.com/container-engine/


SQL-specific commands are accessed by executing the <code>gcloud sql</code> command.
Link to container engine documentation: https://cloud.google.com/container-engine/docs/
 
Some things you can do:
* Manage specific databases
* Back up databases
* Perform Cloud SQL operations
* Connect to Cloud SQL instances
 
Link to gcloud sql command documentation: https://cloud.google.com/sdk/gcloud/reference/sql/


==Connect to MySQL Compute Instance==
==Connect to MySQL Compute Instance==
Line 89: Line 82:
Once you've created the MySQL compute instance, you have a MySQL server running, and you can connect to the server using MySQL clients.
Once you've created the MySQL compute instance, you have a MySQL server running, and you can connect to the server using MySQL clients.


There are (multiple?) ways to do this:  
There are multiple ways to do this:  
* Use the web console to get a shell on the cloud instance using the little cloud shell icon, then use the <code>gcloud sql</code> command
* Log into Google Cloud console, find the compute engine instance, and get a shell on the machine via the browser
* Connect to the MySQL server instance from a MySQL client instance by setting the proper connection parameters
* Connect to the MySQL server instance (in the cloud) from a MySQL client instance (on your local machine) by setting the proper connection parameters


How to connect to a remote MySQL server: [[MySQL#Get_a_remote_MySQL_shell]] (basically, just specify --host and --port arguments)
How to connect to a remote MySQL server: [[MySQL#Get_a_remote_MySQL_shell]] (basically, just specify --host and --port arguments)
Link to Cloud SQL for MySQL that mentions the web console method: https://cloud.google.com/sql/docs/mysql/quickstart


Now, can perform actions like creating a database, inserting sample data, etc.
Now, can perform actions like creating a database, inserting sample data, etc.
Line 112: Line 103:
</pre>
</pre>


Basic operations like configuring users [https://cloud.google.com/sql/docs/mysql/create-manage-users] and creating databases [https://cloud.google.com/sql/docs/mysql/create-manage-databases] can be done using the standard MySQL client, or the web console.
Basic operations like configuring users [https://cloud.google.com/sql/docs/mysql/create-manage-users] and creating databases [https://cloud.google.com/sql/docs/mysql/create-manage-databases] can be done using the standard MySQL client.


===Connecting to MySQL Compute Instance from External Application===
===Connecting to MySQL Compute Instance from External Application===


Can also connect to MySqL compute instance from an external application like JDBC (Java), Go, Docker, or a secure SSL proxy.
Can also connect to MySQL compute instance from an external application like JDBC (Java), Go, Docker, or a secure SSL proxy.


Link with list of external applications: https://cloud.google.com/sql/docs/mysql/external-connection-methods
To connect via a secure SSL proxy, the client machine and server machine must both be running Cloud Proxy: https://cloud.google.com/sql/docs/mysql/sql-proxy


Link with info about SSL proxy for secure connections to compute instances (need proxy server running on both client and server): https://cloud.google.com/sql/docs/mysql/sql-proxy
(NOTE: Not trivial to carry out successfully!)


===Configuring Default User===
===Configuring Default User===


The one operation that is not performed using a standard MySQL client or standard MySQL commands is configuring the default user account. This is required before you can connect to the instance. By default, the default user is root.
Configure the default user account. By default, the default user is root.
 
To configure the default user, can use the <code>gcloud sql</code> command:
 
<pre>
$ gcloud sql users set-password root % \
--instance dummy --password YOUR-SECRET-PASSWORD-HERE
</pre>


==Delete MySQL Compute Instance==
==Delete MySQL Compute Instance==
Line 138: Line 122:


<pre>
<pre>
$ gcloud compute instances delete dummy --zone the-zone
$ gcloud compute instances delete dummy --zone us-west1
</pre>
</pre>


Line 145: Line 129:


[[Category:Google Cloud]]
[[Category:Google Cloud]]
[[Category:SQL]]
[[Category:MySQL]]
[[Category:Databases]]

Latest revision as of 07:37, 24 October 2017

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

Manually Allocate Instance and Install MySQL

Start by setting up project:

$ gcloud config set project project-name

Set up compute zone:

$ gcloud config set compute --zone us-west1

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.

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;

Use Container

The other option here, which I suppose would bypass all of the Cloud SQL stuff, is to just use a Docker container and set up the SQL server yourself. This would use the Container Engine product instead.

Link to info about container engine: https://cloud.google.com/container-engine/

Link to container engine documentation: https://cloud.google.com/container-engine/docs/

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.

There are multiple ways to do this:

  • Log into Google Cloud console, find the compute engine instance, and get a shell on the machine via the browser
  • Connect to the MySQL server instance (in the cloud) from a MySQL client instance (on your local machine) by setting the proper connection parameters

How to connect to a remote MySQL server: MySQL#Get_a_remote_MySQL_shell (basically, just specify --host and --port arguments)

Now, can perform actions like creating a database, inserting sample data, etc.

mysql> CREATE DATABASE guestbook;

mysql> USE guestbook;

mysql> CREATE TABLE entries (guestName VARCHAR(255), content VARCHAR(255), 
    entryID INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(entryID));
    INSERT INTO entries (guestName, content) values ("first guest", "First!");
    INSERT INTO entries (guestName, content) values ("second guest", "What a jerk.");

mysql> SELECT * FROM entries;

Basic operations like configuring users [1] and creating databases [2] can be done using the standard MySQL client.

Connecting to MySQL Compute Instance from External Application

Can also connect to MySQL compute instance from an external application like JDBC (Java), Go, Docker, or a secure SSL proxy.

To connect via a secure SSL proxy, the client machine and server machine must both be running Cloud Proxy: https://cloud.google.com/sql/docs/mysql/sql-proxy

(NOTE: Not trivial to carry out successfully!)

Configuring Default User

Configure the default user account. By default, the default user is root.

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 us-west1

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