Home / Localhost / MySQL access denied

MySQL: Access denied for user 'root'@'localhost'

Fix error 1045. Default passwords for XAMPP and MAMP, and how to log in on Linux where root uses socket login.

MySQL error 1045: access denied for user root at localhost, which usually means a wrong password

MySQL error 1045 means the username or password was rejected. The right login depends on your setup, so check the defaults below first.

Default logins

Create your own user

Log in on Linux
sudo mysql
Create a normal user (inside MySQL)
CREATE USER 'app'@'localhost' IDENTIFIED BY 'Change-me-123';
GRANT ALL PRIVILEGES ON appdb.* TO 'app'@'localhost';
FLUSH PRIVILEGES;

More things to check

Your app still gets access denied
The username and password in your app’s config must match exactly. Check the .env or wp-config.php file.
phpMyAdmin cannot log in
If you changed the root password, update config.inc.php in the phpMyAdmin folder.
Forgot the root password
Stop MySQL, start it with --skip-grant-tables, log in, set a new password, then restart normally. Only do this on your own computer.
Use a separate user
Create one user per project instead of using root everywhere. See the .env generator.

Questions about MySQL access denied

What is the default MySQL root password in XAMPP?
It is empty. The user is root with no password.
How do I fix MySQL error 1045?
Use the correct password for your setup. On Linux, log in with sudo mysql and create a normal user for your project.

Updated 2026-10-02

Config generators for this

Related pages