
Are you getting the following error when trying to login to the MySQL root on an Ubuntu system or other Linux distribution? We'll show you how to clear it up in a matter of seconds.
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
Explanation: This error is caused by the auth_socket plugin. The simplest solution is to just disable the plugin which we will show you how to do below.
MySQL Server
In this section, we will fix the ERROR 1698
for a MySQL Server installation:
Step 1. Log in to MySQL as root (using sudo
will bypass MySQL's password prompt):
$ sudo mysql -u root
Step 2. Change to the mysql
database and set the plugin to mysql_native_password
for the root user:
mysql> USE mysql; mysql> UPDATE user SET plugin='mysql_native_password' WHERE User='root'; mysql> FLUSH PRIVILEGES;
Step 3. You have to change the root password for this to work. Even just specifying the current password is fine too, but this command must be executed:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password_here'; mysql> exit;
Step 4. Lastly, restart MySQL for the changes to take effect:
$ sudo systemctl restart mysql
Step 5. You can now log in to MySQL root as normal, and will no longer encounter the error:
$ mysql -u root -p
MariaDB Server
In this section, we will fix the ERROR 1698
for a MariaDB Server installation:
Step 1. The solution for MariaDB is different. Users need to run through initial setup by executing:
$ sudo mysql_secure_installation
Step 2. Press enter when prompted for root password:
Enter current password for root (enter for none):
Step 3. Answer N when asked to enable unix_socket
authentication:
Switch to unix_socket authentication [Y/n] n
Step 4. Answer Y when asked if you'd like to change the root password, then supply a new password:
Change the root password? [Y/n] y New password: Re-enter new password:
Step 5. Go through the next few questions, eventually ending by answering Y to reload table privileges:
Reload privilege tables now? [Y/n] y
Step 6. You can now log in to MariaDB root as normal, and will no longer encounter the error:
$ mysql -u root -p
Did this work for you? Let us know in the comments below! Include your system information for help with troubleshooting.
Comments
Comments received on this article:
#1 - jared - September 12, 2022
Thank you it worked for me logging into mysql workbench on linux mint 21
#2 - Abayomi - December 21, 2022
Thank you, this worked for me using Ubuntu 22.04 and I was able to login to my mysql-workbench-community too.
#3 - Bill - May 31, 2023
These are my results.
Clean install of Linux Mint21.1 (Vera) followed by timeshift restore from another server (without replace of /var/lib/mysql contents).
$ sudo mysql -u root
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 33
Server version: 10.6.12-MariaDB-0ubuntu0.22.04.1 Ubuntu 22.04
MariaDB [(none)]> use mysql;
Database changed
MariaDB [mysql]> update user set plugin='mysql_native_password' WHERE user='root';
ERROR 1356 (HY000): View 'mysql.user' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
MariaDB [mysql]> alter user 'root@localhost' identified by 'abc123';
ERROR 1396 (HY000): Operation ALTER USER failed for 'root@localhost'@'%'
MariaDB [mysql]> select User,Password,Host,plugin,authentication_string from user;
+————-+———————————+—————+———————–+————————————–+
| User | Password | Host | plugin | authentication_string |
+————-+———————————+—————+———————–+————————————–+
| mariadb.sys | | localhost | mysql_native_password | |
| root | invalid | localhost | mysql_native_password | invalid |
| mysql | invalid | localhost | mysql_native_password | invalid |
| phpmyadmin | * | localhost | mysql_native_password |* |
+————-+———————————+—————+———————–+————————————–+
Editor response: Looks like you're using MariaDB. Turns out that the solution for MariaDB is different than that of MySQL Server. We've updated the tutorial to include a fix for MariaDB as well.