Updated: 11 October 2026 · Applies to: Ubuntu 24.04, Debian 12, AlmaLinux 9 and Rocky Linux 9

ERROR 1045 (28000): Access denied for user 'root'@'localhost' right after installation usually means root does not use a password in the way you tried. What to do depends on what you installed:

  • MariaDB (all distributions) and MySQL on Ubuntu/Debian: root logs in through the system root account. Run sudo mariadb or sudo mysql without -p.
  • MySQL from Oracle's MySQL repository (AlmaLinux/Rocky): a temporary password was generated. Find it with grep 'temporary password' /var/log/mysqld.log, log in with mysql -u root -p, and change it at once: ALTER USER 'root'@'localhost' IDENTIFIED BY 'New-Strong-Password';
  • MySQL from the AlmaLinux/Rocky AppStream: root has no password at first; run mysql_secure_installation to set one.

Then secure the server with mariadb-secure-installation (MariaDB) or mysql_secure_installation (MySQL).

If none of these work, reset the password as described in "How To Reset Your MySQL or MariaDB Root Password on Ubuntu 18.04?".

Note: Applications should never use the root account. Create a separate user for each application with rights on its own database only.

Ucartz services for this topic

Was this answer helpful? 0 Users Found This Useful (0 Votes)