I installed mysql on ubuntu and tried to access mysql.
mysql -u root -p
But I got the following error.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
So I restarted mysql.
Sudo service mysql restart
Then I tried to access mysql again, but faced with a new error.
ERROR 1045 (28000): Access denied for user 'root'@'localhost'
By googling, I read that this error appears because of the type of the password.
So I changed it.
Firstly, I got into mysql with sudo commend.
Sudo mysql -u root
Then I checked the type of the password.
SELECT User, plugin FROM mysql.user;
The password type of user 'root' was 'auth_socket'.
I changed this to 'mysql_native_password'.
UPDATE mysql.user SET plugin='mysql_native_password' WHERE User='root';
flush privileges;
And then I tried to access mysql.
mysql -u root -p
It worked well.
Top comments (0)