. Advertisement .
..3..
. Advertisement .
..4..
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
Or
Use
service mysql status
to verify your statusEDIT Adding from Comments:
Use:
To continue running MySQL.
This is what I tried before
Next
This is what you need
localhost
should be changed to127.0.0.1
I have checked
http://localhost/phpmyadmin/
againMysqli stated:
I opened
config.inc.php
again 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
Background:
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:
Solution:
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.
config.inc.php
file.$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';
$host
parameter value, use themysqli_connect()
method.$_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_connect
method (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.
Cheers!
This worked well for me.
Find
config.sample.inc.php
Change
In
Save.
Next, rename the file.