How To Change Authentication Plugin Method in MySQL

How To Change Authentication Plugin Method in MySQL

Introduction

In MySQLauth_socket is an authentication plugin. It is a passwordless security mechanism. Authentication Plugin allows MySQL root users to directly login into the MySQL server without a password. It has issues when we need to access MySQL remotely with the root user. Simply enter the following command for Change Authentication Plugin Method in MySQL

mysql

If the Authentication Plugin is Enable then it will directly enter in MySQL server.

Authentication Plugin Method

To Disable Authentication Plugin

To Disable MySQL Root user from directly accessing the MySQL server.

Follow these steps:

  • Check the current status of Authentication Plugin:
select user,authentication_string,plugin,host FROM mysql.user;
how to Change Authentication Plugin Method in MySQL

Authentication Plugin is enabled for MySQL Root User.

  • Disable the Authentication Plugin for MySQL Root User:
alter user 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'hello@123';

Replace hello@123 with your MySQL Root User Password.

Change Authentication Plugin

For MariaDB

  • If you are using the MariaDB then the command will be different. Run the following command to disable the Authentication plugin in MariaDB.
 ALTER USER root@localhost IDENTIFIED VIA mysql_native_password;

Then Set a new password for the MariaDB root user.

ALTER USER 'root'@'localhost' IDENTIFIED BY 'strong_password';
  • Save the changes done in MySQL Server:
flush privileges;
Change Authentication Plugin

Exit from the MySQL Server by Pressing CTRL + D. Now the Authentication Plugin is Disable. Now on you need to use password to access MySQL server.

To Enable Authentication Plugin again

Let’s understand how to enable auth_socket again if we need it later to enable.

To allow MySQL Root users to directly access the MySQL server without entering the Password. Follow the below commands:

  • Check the Status of Authentication Plugin:
select user,authentication_string,plugin,host FROM mysql.user;
Change Authentication Plugin Method in MySQL

Authentication Plugin is Disabled for MySQL Root User.

  • Enable the Authentication Plugin for MySQL Root User:
alter user 'root'@'localhost' IDENTIFIED WITH auth_socket BY 'hello@123';
Change Authentication Plugin

Replace hello@123 with your MySQL Root User Password.

  • Save the changes done on the MySQL Server:
flush privileges;
Change Authentication Plugin Method in MySQL
  • Exit from the MySQL Server by Pressing CTRL + D. Now the Authentication Plugin is successfully enabled.

For MariaDB

  • Login to the MariaDB server.
mysql -u root -p
Change Authentication Plugin
  • First, check the Status of Authentication Plugin.
select user,authentication_string,plugin,host FROM mysql.user;
Change Authentication Plugin
  • Run the following command to enable the Authentication plugin in MariaDB database server.
ALTER USER root@localhost IDENTIFIED VIA unix_socket;
Change Authentication Plugin
  • Save the changes done in MySQL Server:
flush privileges;
Change Authentication Plugin

Exit from the MariaDB Server by Pressing CTRL + D. Now the Authentication Plugin is enabled. Now you can access MariaDB database server without password.

Conclusion

In this Change Authentication Plugin Method in MySQL tutorial, we have learned about auth_socket, how we can enable and disable the Authentication Plugin in MySQL and MariaDB database server. MySQL has a variety of Plugins used in the MySQL server for different purposes. So, we have learned how to enable or disable the auth_socket plugin on MySQL.

If you guys have any queries related to this tutorial, Let me know in the comments.