Search code examples
mysqldatabaseubuntumariadbsudo

Mysql works with sudo, but without not. (ubuntu 16.04, mysql 5.7.12-0ubuntu1.1)


I have Ubuntu 16.04, and Mysql 5.7.12-0ubuntu1.1. When I type:

sudo mysql -u root

I can login into mysql console, but when I type it without sudo:

mysql -u root

I obtain error:

ERROR 1698 (28000): Access denied for user 'root'@'localhost'

My problem occurred when I installed and removed MariaDB. I remember that in PostgreSQL there is important which unix user login to database, but how to handle with this in Mysql?


I solved this problem following by:

https://askubuntu.com/questions/766334/cant-login-as-mysql-user-root-from-normal-user-account-in-ubuntu-16-04


Solution

  • The solution is to provide a password for the root mysql account (if you've not done so already). The error message you're receiving is because a password is required, and you have not provided it. Reset root password with:

    $ mysqladmin -u root password
    $ New password: 
    

    or if you'd already set a root password (which I doubt, otherwise you wouldn't be able to log in via sudo) then it would be

    $ mysqladmin -u root -p  password
    

    Mysql users are not linked with unix users, unlike postgres.