Connecting to CloudSQL from App Engine - mysql

I have a Go app running on App Engine, and a first generation CloudSQL instance running. I can connect to the SQL server from dev using a TCP connection, specifying the SQL server's IP. But I cannot connect from the deployed instance, using the CloudSQL driver.
Sample code
import (
"database/sql"
_ "github.com/ziutek/mymysql/godrv"
_ "google.golang.org/appengine/cloudsql"
)
if (dev) {
sql.Open("mymysql", "tcp:1.2.3.4:3306*database/user/pass")
} else {
sql.Open("mymysql", "cloudsql:project-id:instance-name*database/user/pass")
}
(Yes, I'm substituting database, user, pass, project-id, and instance-name for their correct values in my real code)
When running locally (via goapp serve) I can connect and query the database - everything works great.
However, when connecting from the deployed instance, I get the following error:
Received #1045 error from MySQL server: "Access denied for user 'readonly'#'localhost' (using password: YES)"
I have made sure that my App Engine instance is authorized (SQL > Instance > Access Control > Authorization), and I'm using the same user in both cases.
I've found something resembling my error message on the Diagnosing Issues with Cloud SQL Instances page, but the suggested solution is to connect with SSL if SSL is enabled (I have not enabled SSL for the server).
If you get an error message like:
ERROR 1045 (28000): Access denied for user 'root'#'1.2.3.4' (using password: YES)
when you connect, verify that you are using the correct
password and that you are connecting over SSL if the instance requires
it.
Seeing as how this has given me so much trouble, I also tried connecting via IP address from the App Engine instance, but the socket connection is denied.

Related

Issue connecting AWS EC2 instance to GCP database

We are migrating our database from AWS to GCP. Our website is still hosted on an AWS EC2 instance for the moment.
We have allowed GCP to accept incoming connection from port 3306 with our EC2 instance's IP address.
I can ssh in to our EC2 instance and connect successfully to MySQL from the command line (port 3306), but if I try to connect programmatically on our EC2 instance we get a sql error: "Access denied for user 'my-user-name'#'162.8.X.X' (using password: YES)" (IP address is obviously replaced here).
Access denied means that your application was able to successfully connect to your machine. So you can eliminate any network issues.
Check if your user is allowed to make a connection from that IP.
Do this command to see the users:
SELECT user,host FROM mysql.user;
'my-user-name'#'162.8.X.X' should be in there with either the ip, or with 'my-user-name'#'%'.
If the entry is correct, the only thing remaining to check is to see if the actual password is correct.
Access denied for user is a error coming up from MySQL, so check the MySQL logs or password being passed as if there was a problem with your security group you might have got connection timed out error

Unable to connect to Aurora MYSQL

Hi I have created the Aurora database with MySQL Compatibility. Given public access as this is for the current dev/sample environment. Did not create any VPC, but it uses the default one, for which I have checked the subnets if it has route table to internet gateway and if it is allowing the security group and Network ACL to 0.0.0.0/0 and Mysql port. I dont have firewall blocking the port 3306. It is not serverless as well. I tried to ping and got request timeout from my laptop. Please help. Thanks.
Ping request gives me below error
Request timed out.
Connecting via mysql command gives me below error:
ERROR 1045 (28000): Access denied for user 'admin'#'x.x.x.x' (using password: YES)
Edit
It was confirmed to be a credentials issue, the OP reset their password which resolved the issue.
Original
The error you have is a credentials error, this proves connection between your host and Aurora is possible via the MySQL port.
The following should be checked to resolve the issue:
Check the username, if this was created with the Aurora Cluster check the console to ensure that it is spelt correctly.
Check the password you're entering is correct, if this is the user you created with the Aurora cluster then reset the password from the console.
Regarding ping, the AWS knowledge center says
Amazon RDS doesn't accept internet control message protocol (ICMP) traffic, including ping.
Below is more information about resolving connectivity issues from the knowledge center.

Mysql not accepting connections from some sources

I have a MySQL server (v8.0) running on windows server 2016. I also have IIS running and PHPMyAdmin installed. In addition to this, I have a PHP web application which runs on the same server (under IIS) which accesses the MySQL database. Finally, I have several Python scripts which access the MySQL database.
Somehow, I have lost the ability to access the database from the Python scripts, but the web application still works and PHPMyAdmin can see and modify the database.
Even more strangely, I can no longer user MySQL Workbench to access the server from a PC on the local network, and PHPMyAdmin cannot access the users table of the mysql database. I can't change user details at all through PHPMyAdmin, I get the error:
Error in processing request
Error code: 500
Error text: Internal Server Error (rejected)
It seems that the connection to server has been lost.
MySQL Workbench gives me this error:
Your connection attempt failed for user 'user' to the MySQL server at SERVERADDRESS:PORT:
Access denied for user 'user'#'SERVERADDRESS' (using password: YES)
I have checked that the server can accept connections from remote computers by adding bind-address=0.0.0.0 to the my.ini file. I have also checked to ensure that 3306 is allowed through the firewall.
Any ideas on what could be causing this issue?
ADyson and MrApnea pointed me in the right direction.
The problem was caused by my main database user having the host reset from % to localhost, I'm not sure how this happened or when. As the app was running locally, this was not affected, but all other access was denied (including MySQL workbench). My root user is set to local only for security.
To fix this, I connected to the server via RDP and logged in to the console as the root user. I then ran these commands to see the error:
use mysql;
select host, user from user;
This showed me that the main user account had "localhost" in the host. I ran this command to update this user:
update user set host='%' where user='username' and host='localhost'; flush privileges;

Connect to AWS RDS MySQL from RStudio

I have created an aws account and need to create a connection from RStudio to the aws database in order to write data and read in subsets of the data.
I tried the example here https://shiny.rstudio.com/articles/pool-dplyr.html and it works fine. However, when trying to connect to my own instance I receive the following error:
Error in .local(drv, ...) :
Failed to connect to database: Error: Access denied for user 'Administrator'#'cpc75655-alde5-2-0-cust376.6-2.cable.virginm.net' (using password: YES) .
I have created and assigned my instance to a Security group with Administrator access. What should I try to fix this?
I am working on Ubuntu 16.04.

Cloud SQL database failed to connect from mysql client

I'm unable to connect to Google Cloud SQL from my desktop mysql client. I am also unable to set the sql instance password in google console. It says "instance is busy". I was able to connect to the sql instance using this same command line few weeks ago. Now it's unclear why it is not allowing the same. I see a similar question being asked before but it does not have any resolution.
c:\mysql --host=xxx.xxx.253.xx --user=root --password
ERROR 1045 (28000): Access denied for user 'root'#'xxx.xxx.214.xxx' (using password: NO)
The reason I'm trying to connect from the command line is that my access to the same DB from GAE is also failing with the same error as below.
com.xxx store: java.sql.SQLException: Access denied for user 'root'#'localhost' (using password: YES)
This is the first time I'm trying to access the database from a GAE app. Any idea why the mysql client is not connecting and where I should look to troubleshoot?
Edit:
mysql client connection issue is resolved by upgrading to a newer mysql version (5.6.19). The GAE connection issue persists.
The jdbc url I use is
"jdbc:google:mysql://projid:sqlinstance/dbname?user=root&password=root"
The GAE connection issue was resolved by removing the password from the URL. The new jdbc
url is "jdbc:google:mysql://projid:sqlinstance/dbname?user=root".