You can only connect to root account for MySQL and MariaDB if you are logged in to the system as root user or by using sudo. If not, you will get an access denied error even if you entered the correct password for your root MySQL account.
$ mysql -u root -p Enter password: ERROR 1698 (28000): Access denied for user 'root'@'localhost'
$ sudo mysql -u root -p [sudo] password for user: Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 45 Server version: 8.0.22-0ubuntu0.20.10.2 (Ubuntu) Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. 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>
Amysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY //; Query OK, 0 rows affected (0.01 sec)
Change localhost and password accordingly.
mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec)
$ mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 46 Server version: 8.0.22-0ubuntu0.20.10.2 (Ubuntu) Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. 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>
Comment anonymously. Login not required.