Software⏱️ 2 min read📅 2026-05-31

How to Fix: MYSQL_ROOT_PASSWORD is set but getting "Access denied for user 'root'@'localhost' (using password: YES)" in docker container

MySQL root password not being recognized in Docker container.

Quick Answer: The issue is likely due to the MySQL root user not being created during the image build process. You can try adding a `RUN` command to create the root user and grant it all privileges.

To resolve the issue of 'Access denied for user 'root'@'localhost' (using password: YES)" in Docker container, you need to update the MySQL root user's privileges.

⚠️ Common Causes

  • Incorrect or missing MYSQL_ROOT_PASSWORD environment variable in the Docker container.

🛠️ Step-by-Step Verified Fixes

Method 1: Update MYSQL_ROOT_PASSWORD Environment Variable

  1. Step 1: Run the command `docker-compose exec db mysql -uroot -p${MYSQL_ROOT_PASSWORD}` to verify if the password is correct.

Method 2: Grant All Privileges to MySQL Root User

  1. Step 1: Run the command `docker-compose exec db mysql -uroot -p${MYSQL_ROOT_PASSWORD} --execute=

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions