-
Notifications
You must be signed in to change notification settings - Fork 6
MySQL Setup Guide
Shirley Cohen edited this page Jan 29, 2021
·
8 revisions
Follow this guide to set up your MySQL and Jupyter environments for this class.
- Go to the GCP console.
- From the nav menu, click on APIs & Services and select Library.
- Type Compute Engine API in the search bar and click the Enable button to enable the API.
- Type Cloud SQL Admin API in the search bar and click the Enable button to enable the API.
- From the nav menu, go to IAM and find your default Compute Engine service account. Click on the pencil icon next to it and add the Storage Admin role. Do not remove the Editor role. Save the changes.
- From the nav menu, click on SQL and then click on Create Instance.
- From the create an instance screen, click on Choose MySQL.
- Name your MySQL instance. For example, mysql.
- Set a root password. Make sure you remember it!
- For region, choose us-central1 (Iowa) and Zone, Any.
- For database version, accept the default, MySQL 5.7.
- Click on Configuration options.
- Expand the Connectivity option and uncheck Public IP and check Private IP.
- Expand the Backups, recovery and high availability option and uncheck Enable point-in-time recovery.
- Don't make any other changes.
- Click the Create button to create your MySQL instance.
- While your MySQL instance is being created, go to the Jupyter Setup Guide to set up your Jupyter notebook environment.
- Once your Jupyter environment is running, go to Jupyter Lab.
- Open a terminal window and run
sudo apt-get install default-mysql-client - In your home directory, create a
.my.cnffile with the following content: (Refer to Piazza post @20 for help!)
[mysql]
user=root
password={password}
host={private IP address}
Replace {password} with your actual password and {private IP address} with the IP address of your MySQL instance.
- From terminal, run
chmod 600 ~/.my.cnfto secure your file. - From terminal, run
mysqlto bring up the mysql client. If you're able to connect to your instance, your environment is set up properly. You should see:
jupyter@notebook:~$ mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 31
Server version: 5.7.30-google (Google)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]>
- Once you have tested connectivity, stop your MySQL instance and Jupyter instance. If you forget to stop those resources, you will quickly run out of GCP credits! You'll need to get in the habit of stopping your resources when you are not using them and then restarting them when you are ready to use them again.