简体   繁体   中英

Access denied when connecting to an AWS MySql database from an ASP.NET application

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?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM