MySQL & MariaDB error 1698: Access denied for user (no password used)
Access denied for user 'sockuser'@'localhost' (5.6.51) The account authenticates by operating-system user (auth_socket on MySQL, unix_socket on MariaDB), and you aren't logged in to Linux as that user. Classic case: 'mysql -u root' without sudo on Ubuntu/Debian.
| MySQL | MariaDB | |
|---|---|---|
| Symbol | ER_ACCESS_DENIED_NO_PASSWORD_ERROR | ER_ACCESS_DENIED_NO_PASSWORD_ERROR |
| SQLSTATE | 28000 | 28000 |
| Type | Server error | Server error |
| Versions | since 5.5.63 active | every release since 5.5 active |
What it means
1698 is a “you’re not who this account trusts” error. The account doesn’t check a password: the auth_socket (MySQL) or unix_socket (MariaDB) plugin compares the database user name with the operating-system user of the client process on the other end of the Unix socket. When they don’t match, login fails with 1698 rather than 1045.
Why it happens
- On Ubuntu and Debian, the distribution packages create
'root'@'localhost'with socket authentication.sudo mysqlworks;mysql -u root -pfrom your own login, or from a PHP or Python application, fails with 1698 whatever password you type. - MariaDB 10.4+ creates
root@localhostwithunix_socketor a password, so it works both ways. Other socket-only accounts behave as above. - An account was switched to socket authentication to “secure” it, and an application still uses a password.
- Socket authentication only works over the Unix socket, so a TCP connection (
-h 127.0.0.1) to such an account also fails.
How to fix it
- Run the client as the matching OS user:
sudo mysqlforroot. - Better for applications: don’t use
rootat all. Create a dedicated account with a password:CREATE USER 'app'@'localhost' IDENTIFIED BY '…'; GRANT … ON shop.* TO 'app'@'localhost';. - To give an existing socket account a password, switch its plugin (see the replay below). On MariaDB,
ALTER USER root@localhost IDENTIFIED VIA unix_socket OR mysql_native_password USING PASSWORD('…')keeps both ways of logging in.
Reproduce it yourself
These steps are the exact test our harness runs. Use a scratch server, never production.
Connect with
mysql -u root -pand create a scratch database:CREATE DATABASE demo; USE demo;Create an account that trusts the operating-system user instead of a password. MySQL needs the auth_socket plugin; MariaDB has unix_socket built in.
-- MySQL INSTALL PLUGIN auth_socket SONAME 'auth_socket.so'; CREATE USER 'sockuser'@'localhost' IDENTIFIED WITH auth_socket; -- MariaDB CREATE USER 'sockuser'@'localhost' IDENTIFIED VIA unix_socket;Log in as that account while logged in to Linux as someone else (here, root). This is what happens with 'mysql -u root' on a fresh Ubuntu/Debian install when you are not using sudo.
mysql -u sockuser -e 'SELECT 1'
You get: ERROR 1698 (28000): Access denied for user 'sockuser'@'localhost'(11.8.9)
Verified fixes
Give the account a password-based plugin (or run the client as the matching OS user, e.g. sudo mysql)
Switch the account to password authentication:
-- MySQL 8.0+ ALTER USER 'sockuser'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'Test#1234'; -- MySQL 5.6 (ALTER USER can't change the plugin) UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE user = 'sockuser'; FLUSH PRIVILEGES; SET PASSWORD FOR 'sockuser'@'localhost' = PASSWORD('Test#1234'); -- MySQL 5.7 ALTER USER 'sockuser'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Test#1234'; -- MariaDB ALTER USER 'sockuser'@'localhost' IDENTIFIED VIA mysql_native_password USING PASSWORD('Test#1234');Then log in with the password:
mysql -u sockuser -p -e 'SELECT CURRENT_USER()'
Tested on
| Step | MySQL | MariaDB | |||||||
|---|---|---|---|---|---|---|---|---|---|
| 5.6 | 5.7 | 8.0 | 8.4 | 9 | 10.6 | 10.11 | 11.4 | 11.8 | |
| An account that authenticates by OS user (auth_socket / unix_socket), used from a different OS user repro | ✓ 1698 | ✓ 1698 | ✓ 1698 | ✓ 1698 | ✓ 1698 | ✓ 1698 | ✓ 1698 | ✓ 1698 | ✓ 1698 |
| Give the account a password-based plugin (or run the client as the matching OS user, e.g. sudo mysql) fix | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |