- 3 Minutes to read
- DarkLight
Google Cloud SQL
- 3 Minutes to read
- DarkLight
Google Cloud SQL is a fully-managed database service. It enables users to set up, maintain, and scale relational databases such as MySQL, PostgreSQL, and SQL Server in the cloud, without the need to manage underlying infrastructure, allowing developers to focus on their applications and data rather than database management tasks.
Prerequisites
- You have an access to Google Cloud Console with permissions to provision a SQL Storage.
- You have configured a Google Cloud SQL instance.
- You have configured the network access to the instance.
Authorize Connection to Google Cloud SQL
In Google Cloud Console
Create a Cloud SQL Instance
- In the Google Cloud Console navigate to Storage and SQL.
- Click on Create Instance and choose preferred SQL engine and fill in instance ID, master password, location and database version.
Configure Network Access
- Click on your instance and on the on the detail page, select Edit.
- Find the Connections section and under Public IP add all Dataddo IPs
- Click on Done to save the changes.
Create a Database User
- Select your instance and go to the Users tab.
- Click on Create user account and enter username and password.
In Google Cloud Shell
In order run commands on your database, you need to connect to Google Cloud Shell. This can be done by navigating to detail of your SQL instance and clicking on Open Cloud Shell.
In the Cloud Shell runn the following command to connect to the database. Make sure to replace instance, username and database with the correct values.
gcloud sql connect instance --user=username --database=database
Set User Permissions
Once you created your user and connected to Google Cloud Shell, Use SQL commands to grant the following permissions to your user:
- CREATE,
- SELECT,
- UPDATE,
- INSERT,
- DELETE.
MySQL
Grant Dataddo the CREATE, SELECT, UPDATE, INSERT, DELETE priviledges for your database (please replace database_name with the correct value):
GRANT CREATE ON database_name.* TO 'dataddo'@'%';
GRANT INSERT, UPDATE, DELETE ON database_name.* TO 'dataddo'@'%';
FLUSH PRIVILEGES;
PostgreSQL
Grant Dataddo the SELECT, UPDATE, INSERT, DELETE priviledges for your schema (the example assumes that public schema is used):
GRANT CREATE, USAGE ON SCHEMA public TO dataddo;
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO dataddo;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO dataddo;
SQL Server
Grant Dataddo the CREATE, SELECT, UPDATE, INSERT, DELETE priviledges for your database (please replace database_name with the correct value):
USE [database_name];
GO
-- Grant SELECT, INSERT, UPDATE, DELETE permissions
GRANT SELECT, INSERT, UPDATE, DELETE ON schema::dbo TO [dataddo];
GO
-- Grant CREATE TABLE permission
GRANT CREATE TABLE TO [dataddo];
GO
Create a New Google Cloud SQL
- On the Destinations page, click on the Create Destination button and select the destination from the list.
- Select your authorizer from the drop-down menu.
- Name your destination and click on Save.
Click on Add new Account in drop-down menu during authorizer selection and follow the on-screen prompts. You can also go to the Authorizers tab and click on Add New Service.
Create a New Destination Using Supported Database Engines
After setting up the initial configuration in Google Cloud Console, continue with database engine specific configuration:
Create a Flow to Google Cloud SQL
- Navigate to Flows and click on Create Flow.
- Click on Connect Your Data to add your source(s).
- Click on Connect Your Data Destination to add the destination.
- Choose the write mode and fill in the other required information.
- Check the Data Preview to see if your configuration is correct.
- Name your flow and click on Create Flow to finish the setup.