0

I try to connect my laravel project to myslq on my VPS server . I change the .env file like that :

DB_CONNECTION=mysql
DB_HOST=VPSIpAddress
DB_PORT=3306
DB_DATABASE=DBName
DB_USERNAME=root
DB_PASSWORD=Password

And I clear all cache by artisan , but this way return this error

SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it. (SQL: select * from users where id = 0 limit 1)

Any help please ?

Ahmad Abo Zaid
  • 340
  • 1
  • 16
  • @AlexBarker Thank you for your comment but unfortunately no – Ahmad Abo Zaid Dec 06 '19 at 20:24
  • did you create the account on the mysql server and allow access to that IP, people usually use localhost. Also check the mysql configuration that listens to all interfaces instead of localhost only. – Vidal Dec 06 '19 at 20:38

1 Answers1

1

If you want to change the default behaviour of MySQL that only listen on localhost (127.0.0.1) and make it aviable from the outside Network. You need to edit file /etc/mysql/my.cnf and look for this line bind-address = 127.0.0.1 and make it look like this one:

#bind-address = 127.0.0.1

Also when create the user account you will need to specify the host or ip address or allow all hosts %.

GRANT ALL PRIVILEGES
ON database.*
TO 'user'@'yourremotehost'
IDENTIFIED BY 'newpassword';

Hope it helps.

Vidal
  • 2,605
  • 2
  • 16
  • 32
  • This line I can't find it in /etc/mysql/my.cnf – Ahmad Abo Zaid Dec 06 '19 at 21:20
  • 1
    Thank you , I found it in this path /etc/mysql/mysql.conf.d/mysqld.cnf I change the value of bind-address to 0.0.0.0 and create new user in mysql from this question https://stackoverflow.com/questions/1559955/host-xxx-xx-xxx-xxx-is-not-allowed-to-connect-to-this-mysql-server – Ahmad Abo Zaid Dec 06 '19 at 21:53