Access denied for user 'root'@'localhost' on Ubuntu 24.04
We earn commissions when you shop through the links below.
We made MySQL’s ERROR 1698 on a fresh Ubuntu 24.04, looked up how the account root is checked, and logged in with one command.
Short answer: run sudo mysql instead of
mysql -u root. On 6 October 2026, on a fresh Ubuntu 24.04 with MySQL 8.0.46,
mysql -u root as our own user failed with
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
and sudo mysql logged in. On this install the MySQL account
root is checked by a plugin that compares the account's name with the name
of the system user who runs the command, and sudo runs the command as the
system user root.
What this was run on, and what it does not cover
We ran every command on this page on a fresh virtual machine at a cloud provider, started from Ubuntu's official 24.04 server image, where a script ran the commands and kept everything the machine printed. A block marked Output shows what the command above it printed, or the lines of it that matter, and a line is always shown whole.
date -u +%Y-%m-%d
lsb_release -a
whoami
2026-10-06
Description: Ubuntu 24.04.5 LTS
ubuntu
That is one release of Ubuntu, one machine, one day and one architecture,
x86_64.
We installed MySQL from Ubuntu's archive with the two commands below and changed nothing after that. This is the last line the first one printed.
sudo apt update
32 packages can be upgraded. Run 'apt list --upgradable' to see them.
Then the install. At a terminal apt asks whether to continue, and the script typed
y.
sudo apt install mysql-server
Do you want to continue? [Y/n] y
mysql --version
mysql Ver 8.0.46-0ubuntu0.24.04.4 for Linux on x86_64 ((Ubuntu))
This page covers one cause of the error: that install as it stands, and a login as
root from your own user. It doesn't cover giving root a password,
changing how the account is checked, MySQL's setup script, a user for an application,
MariaDB, or removing MySQL.
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
This is the command that fails, made on purpose: a login as the MySQL account
root, named with -u, run as the system user ubuntu.
mysql -u root
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
Why MySQL refuses
The message doesn't say why. MySQL keeps its accounts in the table
mysql.user, and an account's row says which plugin checks it
(Pluggable Authentication). This is the
row of root; the next section explains the sudo in front.
sudo mysql -e "SELECT user, host, plugin FROM mysql.user WHERE user = 'root';"
+------+-----------+-------------+
| user | host | plugin |
+------+-----------+-------------+
| root | localhost | auth_socket |
+------+-----------+-------------+
On this install, where we set nothing, the plugin is auth_socket. MySQL's manual says what that plugin does: "The socket plugin
checks whether the socket user name (the operating system user name) matches the MySQL user
name specified by the client program to the server"
(Socket Peer-Credential Pluggable
Authentication). The command ran as ubuntu and asked for root,
and those are not the same name.
The fix: ask as the system user root
sudo runs a command as another user
(sudo(8)). With no user named, that was
root here.
sudo whoami
root
Run the MySQL client that way, without -u, and it logs in. At the prompt the
script typed SELECT CURRENT_USER();, which prints the account the server took
you for, and exit, which leaves.
sudo mysql
mysql> SELECT CURRENT_USER();
+----------------+
| CURRENT_USER() |
+----------------+
| root@localhost |
mysql> exit
Bye
The two things we looked at are as before: the row of root still says
auth_socket, and mysql -u root fails as it did.
sudo mysql -e "SELECT user, host, plugin FROM mysql.user WHERE user = 'root';"
+------+-----------+-------------+
| user | host | plugin |
+------+-----------+-------------+
| root | localhost | auth_socket |
+------+-----------+-------------+
mysql -u root
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
So the fix is the other command, not a repair of this one.
The app is free to try in your browser, without an account. To hear when Pro is ready, join the waitlist.
Sources
- Our own run: a script on a fresh Ubuntu 24.04 machine on 6 October 2026. Every command and every output on this page is from the script and its log.
- MySQL 8.0 Reference Manual,
Socket Peer-Credential Pluggable
Authentication: the sentence quoted above;
Pluggable Authentication: the account's
row in
mysql.userand its plugin; and Information Functions: whatCURRENT_USER()returns. - Ubuntu 24.04's manual page sudo(8): the user a command runs as.
- Stack Overflow question 39281594 (2016): where the error is asked about. We took nothing else from it.