MySQL ERROR 1698: Access denied for user 'root'@'localhost' - Rocketeers

 On this page

 Knowledge
---------

MySQL ERROR 1698: Access denied for user 'root'@'localhost'
===========================================================

### [\#Databases](http://rocketee.rs/index.php/databases)

On a fresh Ubuntu install, logging into MySQL as root fails even with the right password. The cause is the auth\_socket plugin, not a wrong password.

 Published by Mark van Eijk on June 23, 2026 · 1 minute read

1. [About the error](#content-about-the-error)
2. [Why do I see this error](#content-why-do-i-see-this-error)
3. [Solution](#content-solution)
4. [Log in the way the plugin expects](#content-log-in-the-way-the-plugin-expects)
5. [Switch root to password authentication](#content-switch-root-to-password-authentication)
6. [Better: create a dedicated app user](#content-better-create-a-dedicated-app-user)

[\#](#content-about-the-error "Permalink")About the error
---------------------------------------------------------

 ```
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

```

You're certain the password is correct, yet `mysql -u root -p` is rejected. This is the signature of the **`auth_socket`** authentication plugin, and it's specifically a 1698, not the [1045 access denied](/sqlstate-hy000-1045-access-denied-for-user) you'd get from genuinely wrong credentials.

[\#](#content-why-do-i-see-this-error "Permalink")Why do I see this error
-------------------------------------------------------------------------

On modern Ubuntu/Debian, the MySQL `root` account is created to authenticate with the `auth_socket` (or `unix_socket`) plugin instead of a password. That plugin checks the **operating system user** running the client: if the OS user is `root`, it lets you in; otherwise it refuses, regardless of any password.

So `mysql -u root -p` as a normal user fails, while `sudo mysql` (running as the OS root) succeeds.

[\#](#content-solution "Permalink")Solution
-------------------------------------------

### [\#](#content-log-in-the-way-the-plugin-expects "Permalink")Log in the way the plugin expects

The quickest path in is simply:

 ```
sudo mysql

```

No password, because `auth_socket` trusts the OS root user.

### [\#](#content-switch-root-to-password-authentication "Permalink")Switch root to password authentication

If you want classic password login (for a GUI client or a remote tool), change the plugin for the root account. Log in with `sudo mysql`, then:

 ```
ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'your-strong-password';
FLUSH PRIVILEGES;

```

On older MySQL/MariaDB use `mysql_native_password` instead of `caching_sha2_password`.

### [\#](#content-better-create-a-dedicated-app-user "Permalink")Better: create a dedicated app user

Rather than handing your application the root account, create a least-privilege user scoped to one database:

 ```
CREATE USER 'app'@'localhost' IDENTIFIED BY 'your-strong-password';
GRANT ALL PRIVILEGES ON my_app.* TO 'app'@'localhost';
FLUSH PRIVILEGES;

```

Then point your app at `app` rather than `root`. See [environment variables in Laravel](/environment-variables-laravel) for wiring the credentials in.

### Subscribe to our newsletter

Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!

  Fill in your email address to receive updates  Subscribe 

#### Related articles

[Stream MySQL backup directly to S3 bucket](http://rocketee.rs/index.php/stream-mysql-backup-s3-bucket)
-------------------------------------------------------------------------------------------------------

On a fresh Ubuntu install, logging into MySQL as root fails even with the right password. The cause is the auth\_socket plugin, not a wrong password.

[Read more →](http://rocketee.rs/index.php/stream-mysql-backup-s3-bucket)

[Export MySQL database using command line](http://rocketee.rs/index.php/export-database-mysql-command-line)
-----------------------------------------------------------------------------------------------------------

On a fresh Ubuntu install, logging into MySQL as root fails even with the right password. The cause is the auth\_socket plugin, not a wrong password.

[Read more →](http://rocketee.rs/index.php/export-database-mysql-command-line)
