This page describes how to connect a
mysql
client,
either running locally on your client machine or in the Cloud Shell,
to your Cloud SQL instance.
Need help? For help troubleshooting the proxy, see Troubleshooting Cloud SQL Proxy connections. Or, see our Cloud SQL Support page.
Before you begin
Before you can start using a client, you must have:
-
Created a Cloud SQL instance, including configuring the default user.
See Creating Instances and Configuring the default user account.
Determined how you will connect to your instance.
For the connection options and how to choose from among them, see Connection Options for External Applications.
Using a local client
Using a local client to connect to your Cloud SQL instance involves three high-level tasks:
- Install the client.
- Configure access to your Cloud SQL instance.
- Connect to your Cloud SQL instance.
Install the client
To install the client:
Debian/Ubuntu
Install the MySQL client from the package manager:
sudo apt-get update sudo apt-get install mariadb-server-10.3
CentOS/RHEL
Install the MySQL client from the package manager:
sudo yum install mysql
openSUSE
Install the MySQL client from the package manager:
sudo zypper install mysql-server
Other platforms
- Download the MySQL Community Server for your platform from the
MySQL Community Server download page.
The Community Server includes the MySQL client. - Install the Community Server, following the directions on the download page.
For more information about installing MySQL, see the MySQL Reference Manual Installing and Upgrading MySQL.
Configure access to your Cloud SQL instance
To configure access to your instance:
- From the client machine, use What's my IP to see the IP address of the client machine.
- Copy that IP address.
- Go to the Cloud SQL Instances page in the Google Cloud Console.
- Click the instance to open its Overview page, and record its IP address.
- Select the Connections tab.
- Under Authorized networks, click Add network and enter the IP address of the machine where the client is installed.
- Click Done. Then click Save at the bottom of the page to save your changes.
- Connect to your instance, either with SSL or without SSL.
Connect to your Cloud SQL instance without encryption
To connect to your instance:
- Confirm that you have installed the client and configured access to your instance.
- Start the mysql client:
mysql --host=[INSTANCE_IP] --user=root --password
- Enter your password.
- The mysql prompt appears.
Connect to your Cloud SQL instance using SSL
To connect using SSL, you need:
- A Certificate Authority (CA) certificate in a server-ca.pem file.
- A client public key certificate in a client-cert.pem file.
- A client private key in a client-key.pem file.
If you lack a client certificate and a corresponding private key, create a new client certificate.
Before you begin, confirm that you have installed the client and configured access to your instance.
To connect to your instance using SSL:
- Start the mysql client:
mysql --ssl-ca=server-ca.pem --ssl-cert=client-cert.pem --ssl-key=client-key.pem \ --host=[INSTANCE_IP] --user=root --password
- Enter the password.
- At the MySQL prompt, enter the
\s
command to verify that your connection is using SSL. -
Look for the output line with SSL:.
... SSL: Cipher in use is DHE-RSA-AES256-SHA ...
For information about troubleshooting connection issues over IP, see Diagnosing Issues with Cloud SQL Instances.
Using the client in the Cloud Shell
- Go to the Google Cloud Console.
- Click the Cloud Shell icon
towards the right in the tool bar. The Cloud Shell takes a few moments to initialize.
- At the Cloud Shell prompt, use the built-in
client to connect to your Cloud SQL instance:
gcloud sql connect [INSTANCE_ID] --user=root
- Enter your password.
The gcloud sql
command group does not support connecting
to a Cloud SQL instance using SSL/TLS.
What's next
- Learn about the two levels of access control for Cloud SQL instances.
- Create users and databases.
- Learn about configuring an instance with a private IP address.
- Learn about options for connecting to your instance from your application.
- Learn about the
mysql
client. - Learn about options for support.