alhelal@VimLaTeX:~$ mysql -u root -p
Enter password: 
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
alhelal@VimLaTeX:~$ sudo mysql -u root -p
[sudo] password for alhelal: 
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 35
Server version: 10.1.29-MariaDB-6 Ubuntu 18.04

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>   

Why mariadb doesn't allow normal ubuntu user to enter mysql as mysql root user?

I also tried ERROR 1698 (28000): Access denied for user 'root'@'localhost' at Ubuntu 18.04 but failed?

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'test'' at line 1
  • Are you still facing this issue? Which SQL query you used in which you got syntax error?
    – Kulfy
    Jun 9, 2020 at 6:14

1 Answer 1


According to this answer from SO, it could be because your root user is using the auth_socket plugin used by default in MySQL/MariaDB on Ubuntu.

$ sudo mysql -u root

MariaDB [mysql]> USE mysql;
MariaDB [mysql]> SELECT User, Host, plugin FROM mysql.user;

| User             | plugin                |
| root             | auth_socket           |

Changing this to mysql_native_password will allow you to connect without requiring sudo:

$ sudo mysql -u root

MariaDB [mysql]> USE mysql;
MariaDB [mysql]> UPDATE user SET plugin='mysql_native_password' WHERE User='root';
MariaDB [mysql]> exit;

$ service mysql restart

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .