Shopware CLI: Access denied for User root@localhost

The problem occurs if the MySQL service cannot be addressed via the DNS name localhost. To increase performance, we activate the skip-name-resolve option in the standard MySQL configuration. As a result, the server can no longer be resolved via DNS name, but also does not perform name resolution per MySQL connection.


Error message

Access denied for 'root'@'localhost'

(When calling a CLI command)



Solution

In the .env or env.local file, the database server is addressed via localhost instead of 127.0.0.1. Adjust the MySQL server host in the .env / .env.local to the value 127.0.0.1.


The Shopware CLI can then be called via bin/console without any problems. If the error still occurs, the Shopware cache may need to be cleared.



Sources

MariaDB documentation (skip-name-resolve)