Error connecting MySQL 8 database

Á

Álvaro Moura

Last updated on Jul 9, 2026

In this tutorial, we will see how to connect to a MySQL database that prohibits access when you have PHP 7 with MySQL 8.


First, you must follow the manual Creating a new MySQL User.

1- Once the creation of the new user has been done, you must go to the path to edit the MySQL configuration file.

Windows: C:\ProgramData\MySQL\MySQL Server[VERSION_HERE]\ my.ini,
OBS: The ProgramData folder is a hidden folder, in order to see it you must access the option Folder > Show hidden files and folders.
Linux: /etc/mysql/my.cnf

2- Then edit the file and where it says

default-authentication-plugin = caching_sha2_password.

Change to

default-autenticação-plugin = mysql_native_password

If you don't find the line above, add this snippet:

[mysqld]  
 default_authentication_plugin= mysql_native_password

Finally, restart the MySQL service in order to enable the new settings.