GAE Python 3.7 Standard can't connect to Cloud SQL server - mysql

I'm following the tutorial for deploying a Django app on Google App Engine here. I'm able to run the app locally using cloud_sql_proxy, but when I deploy the app to GAE the app fails with the error:
(2003, "Can't connect to MySQL server on 'localhost' ([Errno 111] Connection refused)")
Checking the error output, it looks like django is trying to connect to the unix socket at /cloudsql/<project>:<region>:<instance> as expected, it's just failing for some reason. What could be causing this issue?

It looks like the problem was with the project I was using for the tutorial. Somehow the Google App Engine service account for that project had gotten its permissions revoked. After restoring those permissions (giving it the Editor role) the tutorial worked on the original project.

You need to change the database connnection in the Django settings.
appengine/standard_python37/django/mysite/settings.py
The settings.py file contains the configuration for your SQL database. The code in settings.py uses the GAE_APPLICATION environment variable to determine whether the app is running on App Engine or running on your local computer:
When the app runs on App Engine, it connects to the MySQL host by using the /cloudsql Unix socket.
When the app runs on your local computer, it connects to the MySQL host by using TCP, which requires a username and password.
Read the bottom of the documentation, here
Edit: make sure you've enabled the Cloud SQL API.

Related

Azure web app with MySQL cannot connect to database through Virtual Network Service Endpoints

I have a PHP web app (Snipe-IT) that was previously working.
We went through a security review, and the recommendation was made to enable service endpoints (Microsoft.Sql) on the application subnet so that web apps connect to databases over the Azure backbone. Everything is working fine for the other MSSQL apps, except for our Snipe-IT application, which connects to a GP_Gen5_2 MySQL instance.
The error message says:
D'oh! Looks like we can't connect to your database. Please update your database settings in your .env file. Your database says:
SQLSTATE[HY000] [9009] Client connections to Basic tier servers through Virtual Network Service Endpoints are not supported. Virtual Network Service Endpoints are supported for General Purpose and Memory Optimized severs. (SQL: select 2 + 2)
This error message doesn't match the environment configuration because the database in question is a General Purpose, 2 vCore(s), 50 GB database.
There is no networking tab on the MySQL server, but in the Connection security tab we have tried enabling access to Azure resources, allowing the full public internet (0.0.0.0 - 255.255.255.255), enabling and disabling forced SSL, but nothing changes the result.
Azure won't let us create a Private Endpoint on the MySQL database because 'the subnet contains external resources'
I am hoping there is a way to resolve this without having to rebuild both the app and database in a different App Service Environment and subnet.
Thanks

Connect to Google Cloud MySQL instance from local running NodeJS / TypeORM

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.

Connecting to azure's "MySQL in app" database through a remote console

I have a web app in azure, of the MySQL in app type, it is a server with an instance of MySQL but the problem is that I can only manage the DB with PHPMyAdmin and I prefer to use the shell, so my question would be where can I verify the host, the user and the password that I must use to access from a console remotely?
According to this original App Service announcement for in-app MySql in 2016:
MySQL database cannot be accessed remotely. You can only access your
database content using PHPMyadmin or using MySQL utilities in KUDU
debug console.
And also
The database is protected by our sandbox environment and hence cannot
be accessed remotely through MySQL workbench or MySQL command line
tools (running on remote machine).
It would appear that this limitation is still in place.
For anyone who stumbled on this, to access the DB using PHP, use
https://name-of-your-site.scm.azurewebsites.net/phpmyadmin/index.php
Took me a while to find it,
You should get all these information looking in your Azure Portal, the "SQL Databases".
In the Overview menu, you'll get a Connection strings link with all the information you need.
Edit: and then you will be able to use this Connection Strings inside your application.

could not access azure mysql

I have a MySQL server database running on Azure. It has already running to store data from my ASPX web apps hosted on Azure also. I have plan to migrate the apps to Java JSF or .net core.
I developed using Tomcat server (in my local pc) and try to connect directly to mySql in Azure. But I always get Communications link failure error.
Is it not allow to connect directly from my local Tomcat server to database in Azure, or something else?
Thank you in advance for the answer.
Yes you can connect from your local tomcat to your azure mysql if you have provided the correct connection string.
Also add your ip in the firewall rules of the sql resource.

ssh connection spits out sql client connection logging, how do i stop this?

I'm Running Linux Ubuntu 16.04 LTS on google cloud compute engine. this server hosts a website which in turn uses the sql client to connect to a sql instance also running on google cloud platform. I connect to the webserver using ssh which all is fine until I connect to the sql instance.
once this connection is made and the website also can connect to the database my screen is flooded with messages like:
2017/07/12 16:56:30 New connection for
"snappy-gantry-xxxxxx:europe-west1:xxxxx" 2017/07/12 16:56:30 Client
closed local connection on
/cloudsql/snappy-gantry-xxxxxx:europe-west1:xxxxx
This makes it undo-able for me to continue working on this machine. How can i disable this so i can continue my work?
As it is the server is still in development. when it goes to production is don't mind it but even then i don't need those messages.
The problem doesnt occur anymore. What i first did was setting up the connection with sql under my own user account which then spit out the logging. I now started it under the service account and when i log in under my own name i don't see the logging anymore.