Daniel Daniel - 5 months ago 25
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
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:


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

Answer

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.