Connect using a MySQL client 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. Thispage describes how to connect amysql 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 begin
Before you can use amysql client to connect to your Cloud SQLinstance, do the following:
Create a Cloud SQL instance, including configuring the default user.
See Create instances andSet the password for the default user account.
Optionally, create a Compute Engine VM instance and then connected to the instance using SSH.
SeeCreate and start a VM instance,About SSH connections, orConnect to Windows VMs using RDP.
Determine how you'll connect to your instance.
For the connection options and how to choose from among them, seeAbout connection options.
Use a MySQL client on a local machine or a Compute Engine VM
Using amysql client to connect to your Cloud SQLinstance involves three high-level tasks:
Install the client
To install themysql client, do the following:
- Download the MySQL Community Server for your platform from theMySQL 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, seeInstalling and Upgrading MySQL.
Configure access to your Cloud SQLinstance
To configure access to your instance, do the following:
- From the client machine or Compute Engine VM instance, useWhat's my IP to see the IP address of the client machine.
- Copy that IP address.
In the Google Cloud console, go to theCloud SQL Instances page.
- To open theOverview page of an instance, click the instance name.
- SelectConnections from the SQL navigation menu.
- Select theNetworking tab.
- In theAuthorized networks section, clickAdd network and enter the IP address of the machine where the client is installed.Note: The IP address of the instance and the
mysqlclient IP address you authorize must be thesame IP version: either IPv4 or IPv6. - ClickDone. Then clickSave at the bottom of the page to save your changes.
- Connect to your instance, eitherusing SSL/TLS orwithout encryption (without using SSL/TLS).
Connect to your Cloud SQL instance withoutencryption
Caution: This procedure configures an unencrypted connection to your database. If your database contains sensitive data, thenconnect to your instance using SSL/TLS.To let you connect without encryption, the instance must haveSSL modeset toALLOW_UNENCRYPTED_AND_ENCRYPTED. In the Google Cloud console,the equivalent configuration isAllow unencrypted network traffic.
For more information about the SSL/TLS configuration of your instance, seeConfigure SSL/TLS certificates.
To connect to your instance, do the following:
- Confirm that you haveinstalled the client andconfigured access to your instance.
- Start the
mysqlclient:mysql--ssl-mode=DISABLED--host=INSTANCE_IP_ADDRESS--user=root--password
- Enter your password.
- The mysql prompt appears.
Connect to your Cloud SQL instance using SSL/TLS
Note: If you are using IAM database authentication to log in to theinstance, then use the procedure inLog in using IAM database authentication instead.To connect to your instance using SSL/TLS and built-in authentication:
Before you begin, confirm that you haveinstalled the client andconfigured access to your instance.
- Start the
mysqlclient: Warning: Don't include themysql--ssl-mode=REQUIRED\--host=INSTANCE_IP_ADDRESS\--user=root--password
--ssl-modeflag in the command if you are using a MariaDB client to connect to the MySQL instance. Use the client from theMySQL community server instead. - Enter the password.
- At the MySQL prompt, enter the
\scommand to verify that yourconnection is using SSL/TLS. - Look for the output line withSSL:.
Warning: MySQL client versions prior to 5.7.3 consider the...SSL: Cipher in use is DHE-RSA-AES256-SHA...
--ssloptions 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, seeConfiguring SSL for Instances).For information about troubleshooting connection issues, seeDebug connectionissues.
Connect to your Cloud SQL instance using SSL/TLS and client certificate verification
Ifssl_mode on your Cloud SQL instance is configured toTRUSTED_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:
- A client public key certificate in aclient-cert.pem file.
- A client private key in aclient-key.pem file.
In addition, to let the client verify the server's identityfor mutual authentication, specify the server certificateserver-ca.pem.
For example, to start themysql 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 correspondingprivate key, thencreate a new client certificate.
Using the client in the Cloud Shell
To connect to a Cloud SQL instance (public IP only):
- Go to the Google Cloud console.
- Click the Cloud Shell icon
towards the right in the toolbar. 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:
gcloudsqlconnectINSTANCE_ID\--user=root
- Enter your password.
Thegcloud 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:
- Install the proxy (Linux 64-bit) in the
/home/USERdirectory. - Start the proxy, using gcloud CLI authentication:
./cloud-sql-proxyINSTANCE_CONNECTION_NAME &
- Connect to the database by using the TCP connection:
mysql -uUSERNAME -p --host=127.0.0.1
What's next
- Learn about configuring an instance with a private IP address.
- Learn about options for connecting to your instance from your application.
- Learn about the
mysqlclient.
Try it for yourself
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 theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-15 UTC.