Mysql – phpMyAdmin AuthType=config: thesqli_real_connect(): (HY000/2002): No such file or directory

MySQLPHPphpmyadmin

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

Best Answer

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.

Related Topic