0

I have tried many solutions found in stack overflow but still struggling with this problem. The problem is that:

  1. First I have whitelisted my IP to the security group, and public accessibility is Yes. Even I made all traffic access true in the security group.
  2. Then I tried to connect RDS Mysql from my PC's terminal by following command mysql -h ************.rds.amazonaws.com --port=3306 -u username -p Then I successfully connected to the mysql.
  3. But when I try to connect the RDS MySQL database from laravel application from my same PC, it says "SQLSTATE[HY000] [1045] Access denied for user 'username'@'my-pc-ip' (using password: YES) (SQL: select count(*) as aggregate from students)"
  4. I wondered why it is saying username@my-pc-ip instead of username@rds-mysql-host?

.env file

DB_HOST=*******.rds.amazonaws.com
DB_PORT=3306
DB_CONNECTION=mysql
DB_DATABASE=mydb
DB_USERNAME=username
DB_PASSWORD=mypassword

I have also configured the database.php in the config folder.

Any help, please??

I have also same problem from my hosting vps. I also whitelisted my vps's ip in security group and when i tries to connect the mysql from my vps server(not in aws) then it says same problem access denied username@vps-ip.

Any help would be highly appreciated.

2 Answers2

0

This is not a network connection issue, as long as you get an access denied message then your application was able to reach the server

and since you were able to connect using MySQL CLI, try checking passwords for the user as it can be different by connecting client IP

MySQL has two different passwords?

MySQL uses $user/$host/$password comparison by default, so your current setup has two different user accounts in MySQL - root and whatever username you supply on the command line. Each of those has its own password.

AWS PS
  • 4,420
  • 1
  • 9
  • 22
  • You did not answer his #4. It would be interested to know this since I am having same issue. I am able to connect via ssh from my ec2 instance and also I have installed phpmyadmin on the same instance and I am able to connect by entering same username and password there. Any idea?? – Arvind K. Dec 25 '21 at 07:27
  • its not your pc IP, its server IP, you are mixing up – AWS PS Dec 26 '21 at 10:43
  • I was trying to point it towards the fact that when connecting it shows server's or pc's IP, that is, of whichever device you use to connect instead of RDS server IP. This leads the user to think that it might be be trying to connect to local database and not the RDS, hence the question #4 – Arvind K. Dec 28 '21 at 09:58
0

Check your password

Enclose your password within quotes, single or double. For example:

DB_PASSWORD="your_strong_password"

If you password contains any of the quotes used to enclose your password, escape it with a backslash (\). For example:

DB_PASSWORD='your_password\'s_strength'

The answer by @AWS PS is correct, almost. However it does not answer the question #4 raised by asker.

I think the client ec2 IP address shown in the message acts like a client or proxy in order to not disclose the actual RDS server name. Any comment on this would be helpful.

Arvind K.
  • 1,184
  • 2
  • 13
  • 27