If you did a fresh installation on a new Ubuntu (~18.04) version, you may find that it is not possible to log in to MySQL with its root user, unless you do so as Ubuntu’s root user. Here’s how to fix it:
- Log in to MySQL using Ubuntu’s
rootuser.:sudo mysql. - Delete current
root@localhostaccount.:DROP USER 'root'@'localhost';. - Recreate user.:
CREATE USER 'root'@'%' IDENTIFIED BY 'root';. - Grant full permissions.:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;. - Flush privileges.:
FLUSH PRIVILEGES;. - Exit MySQL.:
exit;. - Log in to MySQL without using Ubuntu’s
rootuser. When prompted, enter the password you assigned above.:mysql -u root -p.
Reference: https://askubuntu.com/a/784347/100470.