[Fix] MySQL Docker ERROR 1045 (28000): Access denied for user root@localhost (using password: YES/NO)


If you just installed MySQL image on Docker and then try to access the container and run MySQL command and you get the below 1045 (2800) error,

ERROR 1045 28000 - Access denied for user root MySQL Docker
% mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

% mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Fix:

You need to go to Docker desktop and check for the logs for the MySQL container, you should see the generated root password,

[Entrypoint] Database initialized
mysqld will log errors to /var/lib/mysql/b05e275b7577.err
mysqld is running as pid 68
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
[Entrypoint] GENERATED ROOT PASSWORD: asdQ52ERv=;13AB@j*o=Y2O2j.pl6?@2

You can also access the logs using command: docker logs container_name

Now copy this MySQL root password and run the MySQL command again,

% mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 30
Server version: 8.0.30

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
Advertisements
Try Out Code2care Dev Tools:

Advertisements

Advertisements
Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and software developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include learnings, tutorials, trouble-shooting steps, video tutorials, code snippets, how-to, blogs, articles, etc.

🎉 We are celebrating the 10th years of Code2care! Thank you for all your support!

We strongly support Gender Equality & Diversity.