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 mariadborsudo mysqlwithout-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 withmysql -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_installationto 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
- KVM VPS hosting: NVMe SSD and full root access, with Free Basic Managed Support.
- Unmanaged dedicated servers: full root access and free IPMI KVM, with Free Basic Managed Support.
- Linux server management: hardening, patching, monitoring and automation for Ubuntu, Debian, RHEL and AlmaLinux.
