0

When I attempt to load phpMyAdmin 4.8.0 using AuthType=config I get an error:

Cannot connect: invalid settings. mysqli_real_connect(): (HY000/2002): No such file or directory 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.

The phpMyAdmin config.inc.cfg contains:

$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'MYUSER';
$cfg['Servers'][$i]['password'] = 'MYPASSWORD';
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['connect_type'] = 'socket';
$cfg['Servers'][$i]['socket'] = '/tmp/mysql57.sock';

I can connect to mysql via commandline using socket with same credentials and /tmp/mysql57.sock exists Also:

ps -edf | grep mysql

mysql 18090 17814 0 20:17 ? 00:00:00 /usr/local/mysql57/bin/mysqld --defaults-file=/usr/local/mysql57/my.cnf --basedir=/usr/local/mysql57 --datadir= mysqldata/mysql57 --plugin-dir=/usr/local/mysql57/lib/plugin --log-error=myhost.com.err --pid-file=myhost.com.pid --socket=/tmp/mysql57.sock --port=3306

I have skip-networking in my.cnf so cannot use 127.0.0.1 for host. What can be the problem?

More Details:

Centos 7.4

mysql-5.7.21-linux-glibc2.12-x86_64 (generic binary), community version

PHP 7.2.4

nginx-1.12.2

Hiyo
  • 1
  • 1
  • 1
  • 2
  • What Linux distribution? What MySQL version? Where did you get it? What PHP version? What web server? And include any other details that might be relevant. – Michael Hampton Apr 16 '18 at 20:42
  • I added these details to the bottom of the question. I downloaded MySQL here: https://dev.mysql.com/downloads/mysql/ I can connect using --host localhost -S /tmp/mysql57.sock on commandline. I also have socket defined in 2 places in php.ini – Hiyo Apr 19 '18 at 06:14

4 Answers4

1

My guess is that the PrivateTmp directive is set to yes in the service responsible for PHP runtime, thus defining a separate /tmp directory and preventing PHP from connecting to /tmp/mysql57.sock socket located in system's temporary directory.

There are two possible solutions, which should be applied by extending either nginx.service or php-fpm.service unit. It depends on how nginx is configured to run PHP scripts.

  • Option 1: figure out what systemd unit should be extended and set PrivateTmp=no there.

  • Option 2: configure MySQL to listen to a UNIX socket in another directory located outside /tmp and /var/tmp. I suggest you to use either /run/mysqld.socket or /run/mysqld/mysqld.socket for that.


Reference from systemd.exec(5) manual page:

PrivateTmp=

Takes a boolean argument. If true, sets up a new file system namespace for the executed processes and mounts private /tmp and /var/tmp directories inside it that is not shared by processes outside of the namespace. This is useful to secure access to temporary files of the process, but makes sharing between processes via /tmp or /var/tmp impossible. If this is enabled, all temporary files created by a service in these directories will be removed after the service is stopped. Defaults to false. It is possible to run two or more units within the same private /tmp and /var/tmp namespace by using the JoinsNamespaceOf= directive, see systemd.unit(5) for details. This setting is implied if DynamicUser= is set. For this setting the same restrictions regarding mount propagation and privileges apply as for ReadOnlyPaths= and related calls, see above. Enabling this setting has the side effect of adding Requires= and After= dependencies on all mount units necessary to access /tmp and /var/tmp. Moreover an implicitly After= ordering on systemd-tmpfiles-setup.service(8) is added.

Note that the implementation of this setting might be impossible (for example if mount namespaces are not available), and the unit should be written in a way that does not solely rely on this setting for security.

This option is only available for system services and is not supported for services running in per-user instances of the service manager.

1

If you are using SELinux, check this out.

I had the same problem. I was running CentOS 8 with SELinux enforcing, and I was getting the error mentioned in the question (mysqli_real_connect(): (HY000/2002): No such file or directory) despite having all the configurations fixed correctly. I later got out of trouble after allowing MySQL connections through SELinux.

Check SELinux status using this command:

sestatus

Allow Apache to connect database through SELinux

setsebool httpd_can_network_connect_db 1

Use -P option makes the change permanent. Without this option, the boolean would be reset to 0 at reboot.

setsebool -P httpd_can_network_connect_db 1
Arafat Hasan
  • 111
  • 3
0

For This error you have to restart the service of mysql or which sql you have. Service mysql restart

0

I solved myself for this error do this

In the wp-config.php file, include (or change) this line from

define(‘DB_HOST’, ‘localhost’);

to

define(‘DB_HOST’, ‘127.0.0.1’);
Thomas
  • 4,225
  • 5
  • 23
  • 28