Without sudo login to mysql server in Ubuntu 18

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...

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’

Without sudo login to mysql server in Ubuntu 18

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.

Solution-1

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

Solution-2

Login to mysql using sudo

sudo mysql -u root -p
use mysql
UPDATE user SET plugin=’mysql_native_password’ WHERE User=’root’;
FLUSH PRIVILEGES;

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:

Windows cannot be installed to this disk. the selected disk has an MBR partition table

How to install nginx, mysql, phpmyadmin, php in Ubuntu

How to install IIS Web Server on Amazon EC2 Instance (Windows Server 2008)

Install and configure Jasper Report Server on Ubuntu Server

Kernel for SQL Recovery MVP Product Review

How to install IIS Web Server on Amazon EC2 Instance (Windows Server 2008)

Categories
Linux

I am a proud Indian, proud father, a blogger, Being in a profession as System administrator, my passion is troubleshooting computer issues, I do like sharing solutions through blogging making videos of solving issues.
No Comment

Leave a Reply

*

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.

RELATED BY