Skip to content

Instantly share code, notes, and snippets.

@victorouttes
Created October 15, 2019 09:07
Show Gist options
  • Save victorouttes/7166aa7da9724aba68ca0306677d3045 to your computer and use it in GitHub Desktop.
Save victorouttes/7166aa7da9724aba68ca0306677d3045 to your computer and use it in GitHub Desktop.
Mysql Access denied for user ‘root’@’localhost’.

In Ubuntu systems running MySQL 5.7 (and later), the root user is authenticated by the auth_socket plugin by default.

$ sudo mysql #No Username to be the provide

mysql> USE mysql;

mysql> SELECT User, Host, plugin FROM mysql.user;

+——————+———————–+

| User | plugin |

+——————+———————–+

| root | auth_socket |

| mysql.sys | mysql_native_password |

| debian-sys-maint | mysql_native_password |

+——————+———————–+

mysql> UPDATE user SET plugin=’mysql_native_password’ WHERE User=’root’;

mysql> FLUSH PRIVILEGES;

mysql> exit;

$ service mysql restart

Right Answer!!

If you want to login to your MySQL server as root from an external program such as phpMyAdmin you have two options.

The first one is to change the authentication method from auth_socket to mysql_native_password. You can do that by running the following command: ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘very_strong_password’;FLUSH PRIVILEGES;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment