PHP Connection Failed: Sqlstate[Hy000] [2002] Connection Refused

PHP Connection failed: SQLSTATE[HY000] [2002] Connection refused

I found the reason why the connection was not working, it was because the connection was trying to connect to port 8888, when it needed to connect to port 8889.

$conn = new PDO("mysql:host=$servername;port=8889;dbname=AppDatabase", $username, $password); 

This fixed the problem, although changing the server name to localhost still gives the error.

Connection failed: SQLSTATE[HY000] [2002] No such file or directory

But it connects successfully when the IP address is entered for the server name.

SQLSTATE[HY000] [2002] Connection refused (right port)

Like Sergio Rinaudo said, I had to use the default address instead of "raspberrypi":

$servername = "127.0.0.1";

try {
$pdo = new PDO("mysql:host=$servername;port=3306;database=database", root, M1lVhPuio);

Thank you for your help!

MariaDB with PHP: SQLSTATE[HY000] [2002] Connection refused

I have successfully solved the problem by dumping the database and re-importing it. Maybe 'something' had happened as I exported or imported the database through phpMyadmin.

Using ssh, I did:

mysqldump -u root database > database.sql;

Then login to mysql

mysql -u root; drop database..; create database...; \q; 

Then restore the dump

mysqldump -u root database < database.sql;

Voila! error gone. Whatever devil that was, it kept me busy reinstalling the vps, configuring the server and checking my code for a whole week.

SQLSTATE[HY000] [2002] Connection refused Laravel 8

Basicly problem was i've added read and write ip's in database.php. If you guys are getting this issue, here is some helpful links;

  • https://laradock.io/help/

  • https://www.xspdf.com/resolution/50456690.html

  • https://laracasts.com/discuss/channels/servers/how-to-fix-sqlstatehy000-2002-connection-refused-error

Hope those help. If there is any question, feel free to comment.



Related Topics



Leave a reply



Submit