Issue connecting AWS EC2 instance to GCP database - mysql

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

Related

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: Access denied for user 'user'#'IP_ADDRESS' - Remote access allowed for some hosts fails for other hosts

Background:
I am able to access a mysql instance from some subnets but not others. At least that is what it appears to be.
Machines on network 10.0.21.xx are able to connect to the MySQL instance. But from 10.0.7.xx, I get "Access denied for user using password". Interestingly, MySQL is installed on the same subnet (10.0.7.xx) as the machines that it will not authenticate users from.
Here is the command that I issue.
mysql -u user -h 10.0.7.21 -p
And the error I get is
ERROR 1045 (28000): Access denied for user 'user'#'10.0.7.30' (using password: YES)
I have already checked the /etc/mysql/my.cnf file and made sure that mysqld listens from all IP addresses. I have also checked grant privileges to make sure it is not tied to specific ip addresses.
I'd appreciate if someone can give me additional insight. If you need me to add extra information kindly let me know.
Thanks for reading.
It turns out it was a DNS issue. What led me to go this route is the MySQL Documenation:
If you specify a host name when trying to connect, but get an error message where the host name is not shown or is an IP address, it means that the MySQL server got an error when trying to resolve the IP address of the client host to a name:
One of the solutions it offers is to flush the DNS host cache; in my case I didn't have this table.
Here are recommended fixes from the documentation:
Some permanent solutions are:
Determine what is wrong with your DNS server and fix it.
Specify IP addresses rather than host names in the MySQL grant tables.
Put an entry for the client machine name in /etc/hosts on Unix or
\windows\hosts on Windows.
Start mysqld with the --skip-name-resolve option.
Start mysqld with the --skip-host-cache option.
In my case I added the IP address of our local DNS server to the client's /etc/resolv.cnf file and then restarted network services (service networking restart).
Get the hostname from your error message and add that to your remote sql host access list.
if you error message is Access denied for user 'user'#'10.0.7.30' (using password: YES) then the host name is 10.0.7.30.
Add it to your remote host access list and you should be connected.

Connecting to CloudSQL from App Engine

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.

MySql Remote server connection access denied

I have created a free application using openshift, and created MySQL and phpmyadmin cartridges and inside my phpmyadmin I have gave access to all users from anywhere with all privileges now the problem is when I try to connect from my local MySQL workbench i get connected but I don't see my tables I have created in remote server using phpmyadmin and I can't do any action at all like creating schemas or tables where i get
ERROR 1044: Access denied for user ''#'localhost'
Remember that I allowed all privileges for any user, but I still get access denied for any action except only for the database connection.
Make sure the user you've given full permissions to is the same user MySQL Workbench is connecting as -- there's a difference between the hosts % and localhost for instance. From MySQL Workbench, issue the "Status" command and compare the username and host against what you've configured.
You're apparently connecting through 'localhost' so you have to give full permissions to the anonymous user with host localhost (or change your connection type to tcp so that your connection is via 127.0.0.1 instead of localhost).
Edit for further clarification: The MySQL permission structure treats different types of connections differently; a client connecting via TCP connection always appears to come from an IP address, even if it's from the "local host" (in the sense of being on the same machine), in which case that IP address of the incoming connection may be 127.0.0.1. Socket type connections are registered in MySQL as coming from the host "localhost" (literally, in this case). This is why we're verifying which host MySQL Workbench is connecting as.
Different connection types appear differently to MYSQL even if they're coming from the same "local machine." Furthermore, the wildcard host does not include 'localhost' socket connections, those are a separate entry in the permissions field with the 'localhost' host name; the wildcard does not apply, as I explained above. This is the reason why we're checking which permissions you set against what MySQL Workbench is connecting as; it's the most common cause of difficulties such as these.

How to find the Server Name of MySQL

Where can I find the name of MySQL which I'll use at the connection string to connect to the database from c#?
If you're connecting to a db on the same server, it should be "localhost".
If you are connecting to a remote server, then it should be the FQDN of the remote server (or the IP address) - for example, "dbhost.lan.company.com".
"Unhandled Exception: MySql.Data.MySqlClient.MySqlException: Access denied for user 'root'#'sfn-inkubator-70-61.hib.no' (using password: YES)" error means that you have setup connection address correctly. Client connects to server, but server rejects username and password combination.
So you need to check your server setup, create some user with known password and so on......
It's very possible your host blocks external access to your mysql db, quite a few do. This would explain why you can connect via myadmin.