Without sudo login to MySQL Server in Ubuntu 18
While after successful installation of MySql Server in Ubuntu 18, you receive an error message from the terminal and as well as login from PHPMyAdmin using the browser.
Error – ERROR 1698 (28000) : Access denied for user ‘root’@’localhost’
Checked mysql service using this command and it was running
sudo service mysqld status
I tried with sudo mysql -u root -p and after putting password I could able to login.
It means root user needs sudo permission to login to MySQL.
Create another user and give permission to the required database.
CREATE USER ‘user1’@’localhost’ IDENTIFIED BY ‘password’;
GRANT ALL PRIVILEGES ON database_name.* TO ‘user1’@’localhost’;
now user1 can login without sudo requirement:
mysql -u user1 -p
n:b-user1 is the user name of the new user created
Login to mysql using sudo
sudo mysql -u root -p
UPDATE user SET plugin=’mysql_native_password’ WHERE User=’root’;
After this you can login to MySQL without sudo but there is no password set. So to give a password please do run below command.
mysql> ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘newpassword’;
Have mentioned two solutions to login to MySQL. Hope it will solve the error, in case you find any issue please do add a comment.
You may also like: