Daniel Daniel - 7 months ago 40
SQL Question

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

mysql -u root

I obtain error:

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

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

I solved this problem following by:



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.

$ mysqladmin -u root password 'newpassword'

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'oldpassword' password 'newpassword'

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