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.
change localhost to 127.0.0.1 in config.inc.php
$cfg['Servers'][$i]['host'] = '127.0.0.1';
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.
i'm trying this before
cd /opt/lampp/phpmyadmin
then
gedit config.inc.php
find this,
$cfg['Servers'][$i]['host'] =
if there is localhost
change it to 127.0.0.1
Note : if there is '//' remove // before
$cfg['Servers'][$i]['host']
I checked again http://localhost/phpmyadmin/
mysqli said :
"phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. You should check the host, username and password in your configuration and make sure that they correspond to the information given by the administrator of the MySQL server."
i'm opening again config.inc.php
and i found
$cfg['Servers'][$i]['password'] =
Fill the password with your password
It worked for me. It may work for you too.
phpmyadmin 2018 October
Locate config.sample.inc.php
Change
$cfg['Servers'][$i]['host'] = 'localhost';
into
$cfg['Servers'][$i]['host'] = '127.0.0.1';
Save.
Then rename file and remove sample from the name.
Maybe your SQL server has been stopped
sudo /etc/init.d/mysql start
or
sudo service mysqld start
and useservice mysql status
to check status
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:
mysqli_connect(): (HY000/2002): No such file or directory
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 the mysqli_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.
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 */
$cfg['Servers'][$i]['socket'] = '/tmp/mysql.sock';
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.
First of all, make sure the mysql service is running:
ps elf|grep mysql
you will see an output like this if is running:
4 S root 9642 1 0 80 0 - 2859 do_wai 23:08 pts/0 00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/tomcat-machine.local.pid
4 S mysql 9716 9642 0 80 0 - 200986 poll_s 23:08 pts/0 00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql/tomcat-machine.local.err --pid-file=/var/lib/mysql/tomcat-machine.local.pid
then change localhost to 127.0.0.1 in config.inc.php
$cfg['Servers'][$i]['host'] = '127.0.0.1';
The default password for "root" user is empty "" do not type anything for the password
If it does not allow empty password you need to edit config.inc.php again and change:
$cfg['Servers'][$i]['AllowNoPassword'] = true;
The problem is a combination of config settings and MySQL not running. This was what helped me to fix this error.
I faced this problem on CentOS.
First I try this
sudo service mysql restart
Then error shows up
Redirecting to /bin/systemctl restart mysql.service
Failed to restart mysql.service: Unit not found.
Then I Found this
Command this solve my problem
systemctl start mariadb.service
If you are using archlinux or Ubuntu just type the commands below:
$ cd /opt/lampp/phpmyadmin
then
$ sudo gedit config.inc.php
Then when you access the file look for the scripts below,
//$cfg['Servers'][$i]['host'] ='localhost'
remove '//' so that it remains as shown below:
$cfg['Servers'][$i]['host'] ='localhost'
Then change the 'localhost' to '127.0.0.1' and the script should turn as shown below:
$cfg['Servers'][$i]['host'] ='127.0.0.1'
Get back to your browser and type http://127.0.0.1/phpmyadmin/
If it is still refusing
You should check the host, username and password in your configuration and make sure that they correspond to the information given by the administrator of the MySQL server.
so then get back to the same file config.inc.php you were editing and do as follows:
$ cd /opt/lampp/phpmyadmin
then
$ sudo gedit config.inc.php
search for the script below
$cfg['Servers'][$i]['password'] =''
Fill the password with your root password
$cfg['Servers'][$i]['password'] ='your_password'
And it Should Work. Happy hacking friends.
If your website was running fine and now unexpected ERROR: (HY000/2002): No such file or directory
Then you should NOT CHANGE any configuration file!
First check server error.log file, for Nginx it's located:
/var/log/nginx/error.log
Or for Apache try:
/var/log/apache2/error_log
In my case I could see PHP Fatal error: OUT OF MEMORY in error.log for nginx.
The solution: Add more RAM to server.
I tried to reboot the web server first before upgrading/adding RAM.
Then I got rid of ERROR (HY000/2002) but got some ERROR 50X: Connection Error...
At this point I added 2GB RAM, rebooted the web server and all was working fine!
When the web server was up I noticed 200+ cron-jobs was stuck due to a loop bug in 1 PHP script.
So check which script is consuming memory.
If you used Mac OS and Brew try this:
mkdir /usr/local/etc/my.cnf.d
Try just
sudo service mysql restart
It's work for me
If above solutions doesn't work, try to change the default por from 3306, to another one (i.e. 3307)
You just need to rename ib_logfile0 and ib_logfile1 as ib_logfile_0 and ib_logfile_1. Then your problem would be solved.