How do I connect to Cloud SQL from a GCE instance? I'm getting -bash: mysql: command not found

49 Views Asked by At

I'm following this document Google Cloud - Connect Instance Private IP to connect to my Cloud SQL instance with GCE via private IP.
Both Cloud SQL and GCE are on the same VPC network and in the same region and zone. I've also enabled Cloud SQL Admin API

I got The proxy has started successfully and is ready for new connections! from one of the ssh windows and tried to connect via another ssh window as per the instructions

mysql -u root -p --host 127.0.0.1 --port 3306

but I got

-bash: mysql: command not found

Does anyone know how I can successfully connect?

I tried to install mysql

The error message is still the same:

mysql -u root -p --host 127.0.0.1 --port 3306

-bash: mysql: command not found

1

There are 1 best solutions below

0
Jonathan Hess On

This is Jonathan from Google Cloud SQL Connectors team. I see that you are having a problem with your mysql command. The error you are getting:

-bash: mysql: command not found

means that your shell can't run the mysql command that you installed. To check if this is the problem, run this command:

which mysql || echo 'mysql not found'

If your mysql executable is in the path, then this will print out the absolute path of the mysql executable. If this prints out "mysql not found", then your bash shell can't find the mysql executable.

There are a few ways to solve this. Suppose you downloaded the mysql tar.gz distribution and extracted it into this directory: /home/me/Downloads/mysql-8.0.2

First make sure that the mysql executable is marked as executable on your file system by running the terminal command: chmod a+x /home/me/Downloads/mysql-8.0.2/bin/mysql

Then, there are three ways to update you could update your environment so that you can run the mysql command:

  1. Use the absolute path to the mysql executable, for example: /home/me/Downloads/mysql-8.0.2/bin/mysql -u root -p --host 127.0.0.1 --port 3306 (adjust the path for your system)
  2. Copy the mysql executable into a location in your shell's PATH, cp /home/me/Downloads/mysql-8.0.2/bin/mysql /usr/local/bin &&
  3. Update your path environment variable to include the directory where the mysql file is installed. export PATH=$PATH:/home/me/Downloads/mysql-8.0.2/bin

I hope that helps get you going with Google Cloud SQL.