Troubleshooting ‘Cannot connect to database’ during WordPress installation

Solution:

The issue arises because MySQL 8 uses the caching_sha2_password plugin by default, which older PHP versions (before 7.1.16 or 7.2.4) do not support.

References:

MySQL Caching SHA2 Authentication

PHP mysqli Requirements

Temporary fix:
You can switch the user to mysql_native_password by running this query in the MySQL console:

ALTER USER 'services.com'@'localhost' IDENTIFIED WITH mysql_native_password BY '1111';

Better long-term fix:

1. Edit your MySQL configuration file:

  • Linux: my.cnf
  • Windows: my.ini

2. Add or update the following line:

default_authentication_plugin=mysql_native_password

3.Restart the MySQL server to apply changes.