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
PHP: Storing 'Objects' Inside the $_Session
How to Check What User PHP Is Running As
Header Only Retrieval in PHP Via Curl
How to Check If an Array Value Exists
Pinging an Ip Address Using PHP and Echoing the Result
What Is the Meaning of Three Dots (...) in PHP
How to Tell Which Button Was Clicked in a PHP Form Submit
How to Get Video Duration, Dimension and Size in PHP
Allowed Memory Size of X Bytes Exhausted
How to Prevent Code Injection Attacks in PHP
.Htaccess Rewrite Get Variables
How to Get Const'S Defined on a PHP Class
Does Sleep Time Count For Execution Time Limit
How to Give PHP Write Access to a Directory
Fpdf Error: Some Data Has Already Been Output, Can't Send Pdf