When assigning privileges to a MySQL database user, this is done:
GRANT ALL PRIVILEGES ON databasename
.* TO ‘username’@‘localhost’;
when IPv6 is enabled and prioritized (or IPv4 disabled), as most modern systems will have (Happy Eyeballs), for example PHP will resolve to ::1 and you will get errors like HY000/2002:
Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /home/username/public_html/wp-includes/class-wpdb.php
when you do:
GRANT ALL PRIVILEGES ON
databasename
.* TO ‘username’@‘::1’;
FLUSH PRIVILEGES;
This solves that resolving issue. It would be good if Virtualmin would by default assign (and the other CRUDs; to keep IPv4 in sync) these IPv6 user privileges (until MySQL handles “localhost” better with an upstream solution; but that might not happen, as it would break setups that rely on the distinction).
The goal would be that users can use any of these 4 valid options and get the same result: ::1, 127.0.0.1, ::ffff:127.0.0.1 (IPv4 expressed as IPv6), and localhost.
PS: your “cat /etc/hosts” file should of course also resolve it:
::1 localhost
127.0.0.1 localhost
the order matters in older systems (newer systems often comply with RFC 8305).
PPS: If this does not solve your problem, it might be related to the socket creation. Look into mysqli.default_socket / pdo_mysql.default_socket.