Error "Failed to establish a database connection" in Google Docs Spreadsheet - mysql

I am using xeround for a MySQL database and for the past year I've been connecting to it with Google Apps Script in a Google Docs Spreadsheet. Now all of a sudden it is not connecting. I've checked the username and password, and I've double checked the instance information. I contacted xeround to see if there was a problem with the MySQL database and they say everything is healthy. I'm able to connect with the database through phpMyAdmin using the same user name and password. Here is the code I have in my Google Docs Spreadsheet:
var connectionstring = "jdbc:mysql://instance276.db.xeround.com.:3859/pantalog";
var conn = Jdbc.getConnection(connectionstring, "xxxxxxxxxx", "xxxxxxxxx");
var stmt = conn.createStatement();
The error I get is "Failed to establish a database connection. Check connection string, username and password."
Has Google made some change to JDBC that I'm unaware of?

First thing, there is a typo in that connection string, you shouldn't have that "." before the port number...
var connectionstring = "jdbc:mysql://instance276.db.xeround.com.:3859/pantalog";
should be
var connectionstring = "jdbc:mysql://instance276.db.xeround.com:3859/pantalog";
In case that was just a typo...
I have been having the same kind of problems lately, and think this is actually a DNS problem! (yes I know that sounds like it is impossible).
I get the same error using the DNS entry for my MySQL server.
I then do a nslookup using google's DNS servers (8.8.8.8) and take that IP address, and use it in the connection string instead...
That DNS name resolves to 107.22.255.231
Then it works
Bizarre, I know, but give it a try.
Also, I hope that is not your real username and password in the post :)

This solution worked for me. Substitute the hostname with the IP in the connection string fixes the issue. Seems the resolver in the JDBC is broken.

I found JDBC in Google Sheets to be quite buggy, so I built SeekWell which lets you automatically send data from MySQL to Sheets and can also sync changes from Sheets back to a database. You can schedule refreshes daily, hourly or every five minutes.
Disclaimer: I built this.

Related

Error “Failed to establish a database connection. Check connection string, username and password

I have used IP-Address, google script still gives "failed to establish a connection, invalid connection string, username or password", I have cross-checked data, and mysql port..everything is ok.. but still problem remains. HELP
The workaround appears to be adding ?useSSL=false to the URL:
var dbUrl = "jdbc:mysql://" + IP + ":3306/" + DBNAME + "?useSSL=false";
It is working for me that way now. I am not using Google cloud mysql but another third party mysql.
This appears to be a bug.
This was reported several times in Issue Tracker during the last few days:
AppScripts get a "Failed to establish a database connection. Check connection string, username and password."
This was already reported internally by Google and any updates about this will be communicated there. Please consider subscribing to this issue by starring it in order to keep track of this and to help prioritizing it.

What is the connection string for Google Cloud mySQL, in node.js?

The scenario is as follows:
I am writing an node.js app locally and want it (the mySQL modul, rather) to connect to a mySQL db running on Google Cloud Platform.
I can not get the connection string right and keep getting errors. GCP holds two names for the database - one i picked, one generated, more complex. Problably I should supply one of these into the connection string as "database", the host is likely the IP address with port (or not(?)), I am not sure what the "user" should be, or if it is necessary. Not enough info on the GCP help pages or elsewhere.
tl;dr: I need the following to connect a node.js app with a mySQL module remotely to a GCP database:
var con = mysql.createConnection({
host:"11.222.333.444:3306",
user: "me"
password:"passwo3d",
database:"projectname-1528892969949:europe-west5:dbname"
});
Thank you!
The raw connection string should look something like: mysql://user:password#localhost:port/db
So I think your code should look something like:
var con = mysql.createConnection({
host:"11.222.333.444", <-- remove the port from your string
user: "me"
password:"passwo3d",
database:"dbname" <-- you have it as the instance name .. its just suppose to be the DB name
});
You can also try connecting to the instance using the cloud proxy setup. You host would just be localhost.
Finally you can always go the GCP console -> go to your instance and open up a shell. I think they print out the gcloud cmd in there and you can copy values from the console as well.
Depending on how you are pushing your code, you may have to change a few connections strings in your manifests as well. If you can share those I can help further.
For that to happen, you have to first enable remote access for your mysql on your GCP. A step by step guide is over here, you can leave the first few steps for installing mysql.

How to connect MySQL and google sheet via JDBC

I am using cafe24 which is the hosting site for mySQL. So, I want to fetch data from mysql to Google Spreadsheet. I know that it can be done via JDBC, so I tried it but the connection error occured Failed to establish a database connection. This is my code for connection.
var conn = Jdbc.getConnection("jdbc:mysql://localhost:3306/show981111",
"show981111", "dyd1#tmdwlsfl");
After then, I found that when using other database
you must whitelist certain IP ranges in your database settings
from google scripts site. However, I don't know how to whitelist certain IP ranges. I found that I can allow the access to MySQL from other IP in the cafe24 site, but I can register only one IP address which is for my IP address.

What is the root error behind "Failed to establish a database connection. Check connection string, username and password."

Looking through google and stackoverflow, I found a number of questions asking about "Failed to establish a database connection. Check connection string, username and password." However, I cannot find anyone that has found what the underlying error is.
I am trying to write my first google script with a database connection; I have a mysql and oracle jdbc getConnection, both of which spawn this error. I have checked, double- and triple-check the connection information to no avail. I know the databases are accessible (can get in through other clients from several different machines like php on a linux box, sql developer on various windows PCs at home and work). How do I determine what the real error is? The error as presented to me is way too generic and abstract.
Environment:
Using a script in a Google Spreadsheet (thus inheriting whatever environment is established by google). I am attempting to use the Google API jdbc and have no further knowledge of the environment variables.
Using the following syntax:
var url = "jdbc:mysql://mysql.cb-pta.com:3306/u4lottery";
var conn = Jdbc.getConnection(url, user, password);
Again, user and password have been verified.
There is a known bug which causes problems with jdbc connections using hostnames. Try using an Ip address instead.
Bizarre, but true.. I lost almost 2 days with this bug....
Here is the link to the bug report....
Just for sake of others finding this older thread. I also had trouble using Apps Script to connect to a Google CloudSQL instance, and had to change from:
Jdbc.getCloudSqlConnection('jdbc:google:rdbms://<IP>/<DB_NAME>', '<USER>', 'PASSWORD');
to standard JDBC MySQL (which worked):
Jdbc.getConnection('jdbc:mysql:// ...same as above...
Also, beware and DO NOT include a '/' behind the DB_NAME - this will also cause failure with user/passwd error message!
One more thing to check is that you have proper firewall settings - to allow access from the source IP you are coming from (in the event of Apps Script, this is likely Google's servers - not you client browser's IP). You may have to open it up to all (0.0.0.0/0)
It might have something to do with your database being behind a firewall. According to Google documentation (in this case, Google Data Studio, but generally applicable): "If your database is behind a firewall, you will need to open access to the all of the following IP addresses. These are used by Data Studio to connect to and query your MySql database."
IP addresses here among other places: https://support.google.com/datastudio/answer/7088031

Google Apps Script JDBC connection error - Amazon RDS MySQL

I followed the Google Apps Script JDBC example shown at https://developers.google.com/apps-script/jdbc but have been unsuccessful connecting to a MySQL database hosted at Amazon. My connection string looks like this (scrubbed):
var conn = Jdbc.getConnection("jdbc:mysql://myAmazonhost:3306/", "myUser", "myPass");
I'm able to connect remotely to the Amazon MySQL database from my development system using both MySQL Workbench and Navicat and have checked/verified the host name, username and password in the Google script.
I added the Google servers listed under Accessing Local Databases to the Amazon Security Group but no luck. I keep getting the error:
Failed to establish a database connection. Check connection string,
username and password.
I'm probably missing something simple. Anyone else connecting from a Google script to an Amazon MySQL database? I'd sure appreciate any advice. Thanks.
(Edit...)
Sorry, I inadvertently removed the database name when I sanitized my example above. The DB name is specified in the code.
var conn = Jdbc.getConnection("jdbc:mysql://myAmazonhost:3306/myDB", "myUser", "myPass");
Twelve hours after I posted this question, the script started working--no database connection errors. I built a report that created a spreadsheet using information retrieved from the Amazon MySQL database. (So cool to see all this working in the cloud.)
But... I hadn't made any changes to the JDBC connection string. And no changes were made to the Security Group configuration on the Amazon side. It just started working.
This morning, I started working on the script. I didn't get very far--the big ugly red database connection error message popped up. No changes to code. It just stopped working. I verified the MySQL database is up and accessible from my desktop admin program. No issues.
Is anyone else experiencing erratic connections from Google scripts to external databases? I'm hoping this is just an isolated glitch.
Turns out that the issue was related to the database engine version. I created a new instance using engine version 5.5.25a and the connection worked. I went back to my original database and modified it from 5.5.8 to 5.5.25a and it worked as well. Not sure what's going on with Google Apps Script but changing the engine version to 5.5.25a fixed the problem.
You have to specify which database to connect to. Try
var conn = Jdbc.getConnection("jdbc:mysql://myAmazonhost:3306/DB_NAME", "myUser", "myPass");