MySql workbench : Access denied for user 'root'@'localhost' in linux

38
17



The reason is that recent Ubuntu installation (maybe others also),
mysql is using by default the UNIX or auth_socket plugin.

1. set root user to mysql_native_password

$ sudo mysql -u root -p # I had to use “sudo” since is new installation

mysql:~ USE mysql;
SELECT User, Host, plugin FROM mysql.user;
mysql:~ UPDATE user SET plugin=’mysql_native_password’ WHERE User=’root’;
mysql:~ FLUSH PRIVILEGES;
mysql:~ exit;

$ service mysql restart

2. Add new db_user with you system_user(recommended)
$ sudo mysql -u root # I had to use “sudo” since is new installation

mysql:~ USE mysql;
mysql:~ CREATE USER ‘YOUR_SYSTEM_USER’@’localhost’ IDENTIFIED BY ”;
mysql:~ GRANT ALL PRIVILEGES ON * . * TO ‘YOUR_SYSTEM_USER’@’localhost’;
mysql:~ UPDATE user SET plugin=’auth_socket’ WHERE User=’YOUR_SYSTEM_USER’;
mysql:~ FLUSH PRIVILEGES;
mysql:~ exit;

$ service mysql restart

Remember that if you use option #2 you’ll have to connect to mysql as your system username (mysql -u YOUR_SYSTEM_USER)

Short further steps
create database,tables,attributes, insert data
MySQL Connector/J use it inside your java project
connect with the path

Nguồn: https://keralafolkloreakademy.com/

Xem thêm bài viết khác: https://keralafolkloreakademy.com/giai-tri/

38 COMMENTS

  1. i think I am the only one who failed. I am using ubuntu 18.04, i do not get any respond back after I enter the commands 🙁

  2. Those of you who are having problem with method 2,
    use "mysqladmin -u [YOUR_USER] password" to create new password for user and that may work.

  3. Hi. Nice video with good content. Can you please let me know how can get password for root. I forgot root password

  4. When i maked my installation, i used ( alter user 'root'@'localhost' identified with mysql_native_password by 'password here' ) and this auth_sockt didn't happen to me. Could be a way, idk

LEAVE A REPLY

Please enter your comment!
Please enter your name here