This is the error I got while logging in as root user to MySQL database for the very first time.
ERROR 1698 (28000): Access denied for user ‘root’@’localhost’
I didn’t do anything wrong while logging in.
$ mysql -u root -p
Enter password:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
Ubuntu uses Unix authorisation socket plugin, which will consider the unix user from which you launch mysql client. So I need to jump in as root to execute mysql client as shown below.
$ sudo mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.26-0ubuntu0.20.04.3 (Ubuntu)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
https://dev.mysql.com/doc/mysql-security-excerpt/8.0/en/socket-pluggable-authentication.html