mysqli_real_connect(): (HY000/2002): No such file or directory
PhpMyAdmin error on MacOS. I want answer I really have no idea what I need to do to resolve this.
mysqli_real_connect(): (HY000/2002): No such file or directory
PhpMyAdmin error on MacOS. I want answer I really have no idea what I need to do to resolve this.
mysqli_connect(): (HY000/2002): No such file or directory
Background:
I was just wanted to run some PHPUnit tests on my Mac, using Terminal. Some of the classes I wanna test was having to connect MySQL DB which was created and managed by PHPMyAdmin, and the web app I was working was working fine in the localhost. So when I ran that testcases I got the following error on my terminal:
Solution:
So with the itchiness I had to resolve it and run my test I searched in few SO Q&A threads and tried out. And a combination of changes worked for me.
config.inc.php
file which relates to PHPMyAdmin.$cfg['Servers'][$i]['host']
mostly this line might have been commented out by default, if so please uncomment it.$cfg['Servers'][$i]['host'] = '127.0.0.1';
$host
parameter value in themysqli_connect()
method to following:$_connection = mysqli_connect(**"localhost: 3306"**, $_mysql_username, $_mysql_password, $_database);
Note: This
3306
is my MySQL port number which is its default. You should better check what's your actual MySQL Port number before going to follow these steps.And that's all. For me only these set of steps worked and nothing else. I ran my Unit Tests and it's working fine and the DB data were also updated properly according to the tests.
Why this works:
The closest reason I could have found is that it works because sometimes the
mysqli_connect
method requires a working socket(IP Address of the DB Host along with the Port number) of the database. So if you have commented out the$cfg['Servers'][$i]['host'] = '127.0.0.1';
line or have set 'localhost' as the value in it, it ignores the port number. But if you wanna use a socket, then you have to use '127.0.0.1' or the real hostname. (for me it appears to be regardless of the default port number we really have, we have to do the above steps.) Read the following link of PHPMyAdmin for further details.Hope this might be helpful to somebody else out there.
Cheers!
I fixed the issue today using the steps below:
If config.inc.php does not exists in phpMyadmin directory Copy config.sample.inc.php to config.inc.php.
Add socket to
/* Server parameters */
Save the file and access phpmyadmin through url.
If you are using the mysql 8.0.12 you should use legacy password encryption as the strong encryption is not supported by the php client.
change localhost to 127.0.0.1 in config.inc.php
The reason for this is that pma tries to connect to the mysql.socket if you use localhost. If you use 127.0.0.1 PMA makes a TCP connection which should work.
Try just
sudo service mysql restart
It's work for me
If you used Mac OS and Brew try this:
If above solutions doesn't work, try to change the default por from 3306, to another one (i.e. 3307)