Note there is a similar post here but not fixing my issue:
I had wamp server which comes with mysql server, the path is there. I installed SDK, able to connect to it:
C:\Program Files (x86)\Google\Cloud SDK>gcloud beta sql connect welynxmysql --user=root
However in Cloud Shell, it throws out an error complaining below:
You need the [cloud_sql_proxy] component to use the sql connect
command. ERROR: (gcloud.beta.sql.connect) The cloud_sql_proxy
component(s) is unavailable through the packaging system you are
currently using. Please consider using a separate installation of the
Cloud SDK created through the default mechanism described at:
https://cloud.google.com/sdk/
What am I missing here? How can I connect to mysql instance/database in Cloud Shell?
Thank you very much.
What am I missing here? How can I connect to mysql instance/database in Cloud Shell?
If you are not able to connect to your Cloud SQL instance, you could try to either follow:
Quickstart for Cloud SQL for MySQL
Quickstart for using the proxy for local testing
You could also try to reset your Cloud Shell (note: this will delete all your files within Cloud Shell) as stated here:
Important: This will permanently delete all files in your home directory.
Then, you could try to do a fresh installation of the Google Cloud's SDK.
If none of those works for you, you could try to authorize your account again within the Cloud Shell as follows:
Before beginning, make sure that your Cloud Shell is using your project. If you are not sure you could also run this command to set your project:
gcloud config set project [PROJECT_ID]
Where PROJECT_ID is the project ID where the Cloud SQL instance is located. Then:
Go to your Cloud Shell and run this command (please notice the sudo at
the beginning):
sudo gcloud auth login
Click on the link displayed on the Cloud Shell and log in with your
Google account.
Copy the code displayed on your screen.
Switch to the Cloud Shell, paste it there and hit enter.
You can now run the command as follows:
gcloud beta sql connect [YOUR_INSTANCE_NAME]
or:
gcloud sql connect [YOUR_INSTANCE_NAME]
Where YOUR_INSTANCE_NAME is the name of your Cloud SQL instance.
I hope it helps.
Related
I am trying to connect to local GCloud MySQL instance from my local machine. I managed to connect to the instance from Workbench. In this answer it says to add a socketPath in extra when creating the config file. But since I'm trying to run this on local machine I tried changing that "/cloud/" path in many ways but didn't succeed.
Can someone please explain how I can connect to GCloud MySQL instance from a local NodeJS project that use TypeORM.
As per the official documentation we can establish a connection to Cloud SQL from an application running outside of Google Cloud Platform in different ways. Now, I went through the documentation and I found that you can use a Proxy if is for local test environment. I successfully reproduced this scenario and I did all the steps that the documentation said. According to my tests, there is no need to change the socket path.
Please let me know how it goes.
If you are running an application locally and want to connect to a Cloud SQL instance, I would recommend the Cloud SQL Proxy. It creates local entrypoint (Unix socket or TCP port, depending on what you tell it) that will authenticate and proxy your connections to your instance.
MacBook-Air-2:~ Owner$ gcloud sql instances describe ahaha-mysql
ERROR: (gcloud.sql.instances.describe) There was no instance found at projects/ahaha-20180621/instances/ahaha-mysql or you are not authorized to access it.
You will need to enable permission for the compute instance to access the cloud sql
Stop the instance
Edit the instance and change the Cloud API access scopes
Enable Cloud SQL
Restart the instance
run gcloud auth login and authenticate as yourself by following the link (you might need to fix it in a text editor) and entering the verification code.
run gcloud sql instances describe ahaha-mysql this should now work
I created a webb app and deployed it at Heroku. So far, so good. Now I need to integrate it with the MySQL database which is located at pythonanywhere.com.
I tried the following command (which is what I managed to find when googling for accessing a remote MySQL database from Heroku):
heroku config:add DATABASE_URL=mysql2://PYTHONANYWHERE_USER:DATABASE-HOST-ADDRESS/DATABASE-NAME--app HEROKU-APP-NAME
Whenever I run this command from the console in Heroku, I get the following message:
bash: heroku: command not found
Have anyone tried connecting to a pythonanywhere MySQL database from Heroku before? Can you show how you did this step-by-step?
The reason why I want to access the PythonAnywhere database (and not just host it on Heroku) is that a lot of the backend is written on PythonAnywhere and stored on that database.
Thanks,
The heroku command is provided by the Heroku CLI, and should be installed and run from your local machine. Running heroku commands directly from a dyno (e.g., via heroku run bash) won't work.
Once you've set DATABASE_URL using heroku config you should be able to access it from your code via process.env.DATABASE_URL.
I'm trying to deploy my Node.js app on Google App Engine and it deployed fine, but it can't connect to Google Cloud SQL for some reason. Here's what it throws:
Error: connect ENOENT /cloudsql/my-project-id:asia-east1:my-sql-instance
Here's how I configured the connection:
if (process.env.INSTANCE_CONNECTION_NAME) {
exports.mysqlConfig = {
user: process.env.GCLOUD_SQL_USERNAME,
password: process.env.GCLOUD_SQL_PASSWORD,
socketPath: '/cloudsql/' + process.env.INSTANCE_CONNECTION_NAME
}
} else {
// Use settings for localhost
}
I'm using node-mysql module to connect to the database.
The App Engine and Cloud SQL are already in the same project.
My theory is that the App Engine and the Cloud SQL has to be in the same project and same region, but I'm not sure.
Check your logs for any errors during startup using:
the following cmd gcloud app logs tail -s default or,
with the log viewer https://console.cloud.google.com/logs/viewer
Chances are that you have not enabled the Cloud SQL API for your project: https://console.developers.google.com/apis/api/sqladmin/overview
make sure you have added following setting in app.yaml
beta_settings:
# The connection name of your instance, available by using
# 'gcloud beta sql instances describe [INSTANCE_NAME]' or from
# the Instance details page in the Google Cloud Platform Console.
cloud_sql_instances: YOUR_INSTANCE_CONNECTION_NAME
ref:https://cloud.google.com/appengine/docs/flexible/nodejs/using-cloud-sql-postgres
Apparently the order you do things matters...
enable Cloud SQL API
then (re)deploy your app (gcloud app deploy)
When I did deploy -> create databases -> enable sql ipi I got the ENOENT error
For anyone using 2nd gen Cloud Functions - they added a portion in the documentation:
If you're using Cloud Functions (2nd gen) and not Cloud Functions (1st
gen), the following are required (also see Configure Cloud Run):
They go on to list the steps required. They're a bit scary, but do work eventually.
(If you find yourself looking for the SQL Connection in the new Cloud Run revision, notice there is a separate "Connections" tab for this)
I'm using google compute engine and have an auto scaling instance group that spins up new VMs as needed all sitting behind a load balancer. I'm also using google's cloud SQL in the same project. The VMs need to connect to the cloud SQL instance.
Since the IPs of the VMs are dynamic I can't just plug in the IPs to the SQL access config so I followed the cloud sql proxy setup along with the notes from this very similar question:
How to connect from a pool of Google Compute Engine instances to Cloud SQL DB in the same project?
I can now log into a single test VM and run:
./cloud_sql_proxy -instances=PROJ_NAME:TIMEZONE:SQL_NAME=tcp:3306
and everything works great and that VM connects to the cloud SQL instance.
The next step is where I'm having issues. How can I setup the VM so it automatically starts up the proxy when it's either built from an instance template or just restarted. The obvious answer seem to be to shove the above in the VM's start-up script but that doesn't seem to be working. So with my single test VM I can SSH into the VM and manually run the cloud_sql_proxy command and all works. If I then include the below in my start-up script and restart the VM it doesn't connect:
#! /bin/bash
./cloud_sql_proxy -instances=PROJ_NAME:TIMEZONE:SQL_NAME=tcp:3306
Any suggestions? I seriously can't believe it's this hard to connect to the SQL cloud from a VM in the same project...
The startup script you have shown doesn’t show the download step of the cloud_sql_proxy.
You need to first download and then launch the proxy. So, your startup script should look like:
sudo wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64
sudo mv cloud_sql_proxy.linux.amd64 cloud_sql_proxy
sudo chmod +x cloud_sql_proxy
sudo ./cloud_sql_proxy -instances=PROJ_NAME:TIMEZONE:SQL_NAME=tcp:3306 &
I choose crontab to run cloud_sql_proxy automatically when vm start up.
$crontab -e
and add
#reboot cloud_sql_proxy blah blah.