xxxxxxxxxx
sudo mysql
-- for MySQL
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
FLUSH PRIVILEGES;
xxxxxxxxxx
# For Linux
sudo mysql
mysql > # run below code
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'insert_password';
# If you want to empty password run this code:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';
xxxxxxxxxx
sudo mysql
-- for MySQL
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
-- for MariaDB
ALTER USER 'root'@'localhost' IDENTIFIED VIA mysql_native_password USING PASSWORD('root');
#With a single query we are changing the auth_plugin to mysql_native_password and setting the root password to root (feel free to change it in the query).
#Now you should be able to log in with root. More information can be found in MySQL documentation or MariaDB documentation.