#1045 - Access denied for user 'root'@'localhost'

phpMyAdmin Root Login Fails After Fresh Install

After installing phpMyAdmin, you get 'Access denied for root'. The fix is usually a config tweak or resetting the MySQL root password. Here's how to fix it fast.

The 30-Second Fix: Check Your Password

You just installed phpMyAdmin. You type 'root' in the username field, leave the password blank (or type something), and get:

#1045 - Access denied for user 'root'@'localhost' (using password: YES/NO)

What's actually happening here is that phpMyAdmin isn't using the same authentication method as your MySQL/MariaDB server. On Ubuntu 20.04+, MariaDB (default) uses unix_socket authentication for root. This means you need to be logged in as the system root user to connect – not possible from the phpMyAdmin web interface.

Try this first: Leave the password field completely blank and hit Go. If you get past the login screen, you're done. That's it – 30 seconds. But if it still fails, move to the next fix.

The 5-Minute Fix: Switch Root to mysql_native_password

The real fix is to change the root user's authentication plugin from unix_socket or auth_socket to the standard mysql_native_password that phpMyAdmin expects.

  1. Open a terminal and log into MySQL as root. Since you can't use phpMyAdmin, you need the command line:
sudo mysql -u root

If that fails, you need to stop MySQL and restart it without authentication (skip-grant-tables). But let's assume it works.

  1. Check the root user's current auth method:
SELECT user, host, plugin FROM mysql.user WHERE user = 'root';

You'll likely see unix_socket or auth_socket. That's your problem.

  1. Switch root to use a password. Replace 'YourPassword' with something strong:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YourPassword';

The reason this works: mysql_native_password is the old-style password hashing that phpMyAdmin has always used. The newer auth plugins require the client to be on the same machine as the server – phpMyAdmin is a web client, so it fails.

  1. Flush privileges and exit:
FLUSH PRIVILEGES;
EXIT;
  1. Now restart MySQL and try logging into phpMyAdmin with the new password:
sudo systemctl restart mysql

This should work. If not, your problem might be something else – check the advanced fix below.

The 15+ Minute Fix: Reset root Password and Fix config.inc.php

If the above fixes didn't work, you likely have one of two issues: the MySQL root password is really unknown, or phpMyAdmin's config file points to the wrong socket.

Forget the root password? Reset it

Skip the password recovery – just reset it:

  1. Stop MySQL:
sudo systemctl stop mysql
  1. Start MySQL in safe mode, skipping grants:
sudo mysqld_safe --skip-grant-tables &

If the command doesn't exist (common on newer versions), use:

sudo mysqld --skip-grant-tables --skip-networking &
  1. Connect without a password:
sudo mysql -u root

Now you're in. Set a new password:

FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'NewPassword';
FLUSH PRIVILEGES;
EXIT;
  1. Kill the safe-mode process and restart normally:
sudo killall mysqld
sudo systemctl start mysql

Fix phpMyAdmin config.inc.php

Sometimes phpMyAdmin uses a wrong socket path. Open its config file:

sudo nano /etc/phpmyadmin/config.inc.php

Look for lines like:

$cfg['Servers'][$i]['socket'] = '/var/run/mysqld/mysqld.sock';

If the socket path is wrong, comment it out or correct it. On Ubuntu, the socket is usually at /var/run/mysqld/mysqld.sock. On Windows, it's not used – instead check the TCP port:

$cfg['Servers'][$i]['host'] = '127.0.0.1';
$cfg['Servers'][$i]['port'] = '3306';

If you're on a fresh install, you might also see:

$cfg['Servers'][$i]['auth_type'] = 'cookie';

This is fine – it means phpMyAdmin asks for login every time. Don't change it to 'config' unless you know what you're doing.

After editing, save and restart Apache (or nginx):

sudo systemctl restart apache2

Try logging in again. If it still fails, check your MySQL logs:

sudo tail -f /var/log/mysql/error.log

Look for lines with 'Access denied' – they tell you exact host and user that failed. Usually it matches the above.

Why This Happens on Fresh Installs

Pop quiz: why does a brand-new MySQL install on Ubuntu 22.04 lock out phpMyAdmin? The answer is the default authentication plugin changed from mysql_native_password to unix_socket in MySQL 8.0 and MariaDB 10.4+. This was a security move – it prevents remote root access and forces Unix domain socket authentication. But phpMyAdmin connects via TCP localhost, which bypasses the socket. The result: denied.

MariaDB's default on Ubuntu is even stricter: the root user has no password at all, and can only connect from the system root account. So when phpMyAdmin asks for a password, any password (or blank) fails.

The moral: after installing phpMyAdmin, always switch root to mysql_native_password unless you plan to only use the console.

Related Errors in Database Errors
0X80110480 Fix COM+ Migration Error 0X80110480 on Windows 0X8004D00B XACT_E_NOISORETAIN (0x8004D00B) — MSDTC Isolation Fix 3154, 3241, 3624, 3013 SQL Restore Fails: Validation Errors & Quick Fixes Connection refused Database Connection Refused After Server Migration — Real Fixes

Was this solution helpful?

EP
Erropedia Team
Tech Support Editors
The Erropedia editorial team researches and documents real-world tech errors from across Windows, Linux, macOS, networking, databases, cloud platforms, and more. Every solution is reviewed for accuracy and updated as software and systems evolve.