Stay organized with collections Save and categorize content based on your preferences.
You can use the MySQL command-line client to connect to Cloud SQL. This page describes how to connect a mysql
client to your Cloud SQL instance, whether running locally on your client machine, on a Compute Engine VM, or in the Cloud Shell.
Before you can use a mysql
client to connect to your Cloud SQL instance, do the following:
Create a Cloud SQL instance, including configuring the default user.
See Create instances and Set the password for the default user account.
Optionally, create a Compute Engine VM instance and then connected to the instance using SSH.
See Create and start a VM instance, About SSH connections, or Connect to Windows VMs using RDP.
Determine how you'll connect to your instance.
For the connection options and how to choose from among them, see About connection options.
Using a mysql
client to connect to your Cloud SQL instance involves three high-level tasks:
To install the mysql
client, do the following:
For more information about installing MySQL, see Installing and Upgrading MySQL.
Configure access to your Cloud SQL instanceTo configure access to your instance, do the following:
In the Google Cloud console, go to the Cloud SQL Instances page.
mysql
client IP address you authorize must be the same IP version: either IPv4 or IPv6.To let you connect without encryption, the instance must have SSL mode set to ALLOW_UNENCRYPTED_AND_ENCRYPTED
. In the Google Cloud console, the equivalent configuration is Allow unencrypted network traffic.
For more information about the SSL/TLS configuration of your instance, see Configure SSL/TLS certificates.
To connect to your instance, do the following:
mysql
client:
mysql --ssl-mode=DISABLED --host=INSTANCE_IP_ADDRESS --user=root --password
To connect to your instance using SSL/TLS and built-in authentication:
Before you begin, confirm that you have installed the client and configured access to your instance.
mysql
client:
mysql --ssl-mode=REQUIRED \ --host=INSTANCE_IP_ADDRESS \ --user=root --passwordWarning: Don't include the
--ssl-mode
flag in the command if you are using a MariaDB client to connect to the MySQL instance. Use the client from the MySQL community server instead.\s
command to verify that your connection is using SSL/TLS.... SSL: Cipher in use is DHE-RSA-AES256-SHA ...Warning: MySQL client versions prior to 5.7.3 consider the
--ssl
options as advisory, and silently fall back to unencrypted connections if the server does not accept an encrypted connection. For more information, see Using Encrypted Connections in the MySQL Reference Manual. To avoid this issue, you can configure the instance so that only SSL/TLS connections can connect to it (for more information, see Configuring SSL for Instances).
For information about troubleshooting connection issues, see Debug connection issues.
If ssl_mode
on your Cloud SQL instance is configured to TRUSTED_CLIENT_CERTIFICATE_REQUIRED
, then you must also provide a verified client identity when you log in.
To connect using SSL/TLS certificates with client verification, you need the following:
In addition, to let the client verify the server's identity for mutual authentication, specify the server certificate server-ca.pem.
For example, to start the
mysql
client:
mysql --ssl-mode=VERIFY_CA \ --ssl-ca=server-ca.pem \ --ssl-cert=client-cert.pem \ --ssl-key=client-key.pem \ --host=INSTANCE_IP_ADDRESS \ --user=root --password
If you do not have a client certificate and a corresponding private key, then create a new client certificate.
Using the client in the Cloud ShellTo connect to a Cloud SQL instance (public IP only):
The Cloud Shell takes a few moments to initialize.
gcloud sql connect INSTANCE_ID \ --user=root
The gcloud sql connect
command does not support connecting to a Cloud SQL instance using private IP, or using SSL/TLS. To connect with encryption, install and use the proxy in the Cloud Shell:
/home/USER
directory../cloud-sql-proxy INSTANCE_CONNECTION_NAME &
mysql -u USERNAME -p --host=127.0.0.1
mysql
client.If you're new to Google Cloud, create an account to evaluate how Cloud SQL performs in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
Try Cloud SQL freeExcept as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-14 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-14 UTC."],[],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4