2

I've just set up a MySQL database in AWS, however every time I try to connect programmatically I get an access denied exception. Connecting through MySQL Workbench works absolutely fine.

I've added my IP address to the Inbound Rules in AWS (without it, Workbench can't connect so it's definitely set up somewhat correctly) and even added a rule to allow all IP addresses for all traffic:

Allow all rule

This is a bare minimum example of what I'm trying to do:

using MySql.Data.MySqlClient;

MySqlConnection connection = new(CONNECTION_STRING);
connection.Open();

which throws the exception on connection.Open().

Connection string:

Server=aa11sgbkk911b5j.cevakqici96g.eu-west-2.rds.amazonaws.com;Database=ebdb;Uid=username;Pwd=password;

The exact exception:

MySql.Data.MySqlClient.MySqlException
  HResult=0x80004005
  Message=Authentication to host 'aa11sgbkk911b5j.cevakqici96g.eu-west-2.rds.amazonaws.com' for user 'username' using method 'mysql_native_password' failed with message: Access denied for user 'burntorangeadmin'@'cpc150000-brnt4-2-0-cust812.5-2.cable.virginm.net' (using password: YES)
  Source=MySql.Data
  ...

Does anyone have any idea why I can't connect?

2
  • 1
    Have you enabled privileges for your user? Commented Mar 27, 2022 at 1:17
  • AWS had additional authentication beyond a connection string. Database, for example, can be locked down so that only specific compute resources are able to connect to them. This article might help: docs.aws.amazon.com/AmazonRDS/latest/UserGuide/… Commented Apr 6, 2022 at 17:30

2 Answers 2

2

I originally had the database coupled to an Elastic Beanstalk instance, and after creating a new one separately everything worked as expected.

So still no actual solution to why it wasn't working in the first place, but decoupling has done the trick.

Sign up to request clarification or add additional context in comments.

Comments

0

Check that you have granted the appropriate privileges to the user account

Eg.

CREATE USER 'cdcuser'@'%' IDENTIFIED WITH mysql_native_password BY "cdcpwd";
GRANT ALL PRIVILEGES ON *.* TO 'cdcuser'@'%' ;
FLUSH PRIVILEGES;

3 Comments

It looks like my user does have all privileges, I tried the GRANT anyway, but still getting the same error. I'm using the same user for the MySQL Workbench and obviously everything is fine for that. Very strange.
Ah glad you got it sorted. Apologies for the unhelpful advice
Always worth trying something! I am still in the dark about what caused the issue in the first place, but maybe this is best left alone!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.