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:
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
Answers
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.
Check that you have granted the appropriate privileges to the user account
Eg.