. Advertisement .
. Advertisement .
Hi everyone, I’m learning about php. While working, I try run PhpMyAdmin on MacOS. As a result, I get the message:
mysqli_real_connect(): (HY000/2002): No such file or directory
What can I do about the “mysqli_real_connect(): (hy000/2002): no such file or directory” issue? Is there a better approach?
change localhost to 127.0.0.1 in /etc/phpmyadmin/config.inc.php
This is because pma attempts to connect to mysql.socket when you use localhost. PMA will establish a TCP connection if you use 127.0.0.1.
Perhaps your SQL server was stopped
service mysql statusto verify your status
EDIT Adding from Comments:
To continue running MySQL.
This is what I tried before
This is what you need
localhostshould be changed to
I have checked
config.inc.phpagain and found it.
Enter your password to create the password
It worked for me. It might work for you.
mysqli_connect() (HY000/2002: No such file/directory
I just wanted to run some PHPUnit testing on my Mac using Terminal. One of the classes that I wanted to test was the ability to connect MySQL DB. This was created and managed PHPMyAdmin. The web app that I was using was fine in localhost. When I tried to run the testcases, I received the following error:
With the itchiness, I needed to find a solution. I also searched in a few SOQ&A threads for help and tried it out. I found that a combination of these changes worked well for me.
$cfg['Servers'][$i]['host']line. This line may have been commented out by default. Please uncomment it.
$cfg['Servers'][$i]['host'] = '127.0.0.1';
$hostparameter value, use the
$_connection = mysqli_connect(**"localhost: 3306"**, $_mysql_username, $_mysql_password, $_database);
Note : This is my default MySQL port number,
3306. Before you follow these steps, make sure to verify your MySQL Port number.
That’s it. These steps were the only ones that worked for me. It worked fine after I ran the Unit Tests. The DB data was also properly updated according to the tests.
This is how it works
It works because sometimes, the
mysqli_connectmethod (IP Address of the DB Host and Port number) requires a working socket. If you’ve commented out
$cfg['Servers'][$i]['host'] = '127.0.0.1';or set ‘localhost” as the value, the port number is ignored. If you want to use a socket, you will need to use ‘127.0.0.1 or the actual hostname. The above steps must be followed regardless of what default port number you have. For more information, please refer to the link in PHPMyAdmin.
We hope this helps someone else.
This worked well for me.
Next, rename the file.