MySQL fails on: mysql "ERROR 1524 (HY000): Plugin 'auth_socket' is not loaded"
Asked Answered
S

13

177

My local environment is:

  • Fresh Ubuntu 16.04
  • With PHP 7
  • With installed MySQL 5.7
sudo apt-get install mysql-common mysql-server

When I tried to login to MySQL (via CLI):

mysql -u root -p

I came across an cyclic issue with 3 steps.

  1. First was some socket issue

    ERROR 2002 (HY000): Can't connect to local MySQL server through    socket '/var/run/mysqld/mysqld.sock'
    

    Solution: Restarting PC.

    Which led to another error:

  2. With access denied

    ERROR 1698 (28000): Access denied for user 'root'@'localhost'.
    

    Possible issue? Wrong password for root user!

    Solution: Reset root password with this RackSpace tutorial. With correct password and working socket, there comes last error.

  3. Incorrect auth plugin

    mysql "ERROR 1524 (HY000): Plugin 'unix_socket' is not loaded"
    

    Here I stopped or somehow got to step 1. again.

Swithbart answered 17/6, 2016 at 10:36 Comment(0)
S
459

I got a solution!

When resetting the root password at step 2), also change the auth plugin to mysql_native_password:

use mysql;
update user set authentication_string=PASSWORD("") where User='root';
update user set plugin="mysql_native_password" where User='root';  # THIS LINE

flush privileges;
quit;

This allowed me to log in successfully!


Full code solution

1. First, run these bash commands

sudo /etc/init.d/mysql stop # stop mysql service
sudo mysqld_safe --skip-grant-tables & # start mysql without password
# enter -> go
mysql -uroot # connect to mysql

2. Then run mysql commands => copy paste this to CLI manually

use mysql; # use mysql table
update user set authentication_string=PASSWORD("") where User='root'; # update password to nothing
update user set plugin="mysql_native_password" where User='root'; # set password resolving to default mechanism for root user

flush privileges;
quit;

3. Run more bash commands

sudo /etc/init.d/mysql stop 
sudo /etc/init.d/mysql start # reset mysql
# try login to database, just press enter at password prompt because your password is now blank
mysql -u root -p 

4. Socket issue (from your comments)

When you see a socket error, a community came with 2 possible solutions:

sudo mkdir -p /var/run/mysqld; sudo chown mysql /var/run/mysqld
sudo mysqld_safe --skip-grant-tables &

(thanks to @Cerin)

Or

mkdir -p /var/run/mysqld && chown mysql:mysql /var/run/mysqld  

(thanks to @Peter Dvukhrechensky)


Blind paths and possible edge errors

Use 127.0.0.1 instead of localhost

mysql -uroot # "-hlocalhost" is default

Can lead to "missing file" or slt error.

mysql -uroot -h127.0.0.1

Works better.

Skip the socket issue

I've found many ways to create mysqld.sock file, change access rights, or symlink it. It was not the issue after all.

Skip the my.cnf file

The issue also was not there. If you are not sure, this might help you.

Swithbart answered 17/6, 2016 at 10:36 Comment(22)
Thank you for this. This is also an excellent answer on how to reset mysql root pass so you might want to slightly edit the title to help it come up before we already run into the socket issue.Towrope
I'm glad it helped. How would you edit the title to keep origin message? I understand the solution requires to reset password, but it does not solve the issue in the title. This is more complex failure of more points. For root password reset, I'd go here: https://mcmap.net/q/57718/-how-to-reset-mysql-root-passwordSwithbart
Thanks this seems to work. Any idea why the plugin definition needs to be tweaked?Linotype
@matanster Not really, this is pure step-by-step trial-fail constructed. What OS do you use?Swithbart
If you cant use mysql_safe here's a way to achieve this using systemctl 'set enviroment' #33510684Plugboard
Your mysqld_safe call is incorrect. You need to instead run: sudo mkdir -p /var/run/mysqld; sudo chown mysql /var/run/mysqld; sudo mysqld_safe --skip-grant-tables &Woodman
The init.d scripts don't work with the mysqld_safe process on Ubuntu 16.Woodman
Worked for me after applying @Cerin's steps. I also recommend changing the second update statement to update user set plugin="mysql_native_password" where User='root'; so it doesn't unintentionally affect other users.Gossamer
@Woodman Thanks for feedback. Can you edit the post and suggest changes? I'd be happy to accept them.Swithbart
@Woodman Did you get my message? I'm not sure what exact lines to replace.Swithbart
yeah, this solution it work for me, thank you. (same problem at macOS sierra 10.12.6, percona 5.7.18-16, installed by homebrew)Soviet
And be sure to re-establish a root password.Agist
You might want to mark this answer as the correct one with greeny, since it indeed is correct :)Intermarry
I am having same issue on windows how to fix thatMartyry
Please add a posible solution of the socket issue to the answer. Like this one mkdir -p /var/run/mysqld && chown mysql:mysql /var/run/mysqld It may save someone's timeSanctimony
Thanks for the comment, I've updated the answer. Is that correct?Swithbart
Perfect Answer.!!!! Have been fiddling with the mysql config for too long, after resetting the root password.Bluetongue
Thanks! This was a super useful discussion. In the end I was not yet able to get my problem fixed with it, but most parts. Combining a couple of approaches I made a shell script that might come in handy for someone in the future: toxyl.github.io/mysql-innodb-recoveryArose
I was not able to stop mysql (step 3) when it was in safe mode (Ubuntu 16), and if you have multiple daemons running you will end up with issues (so be sure it's actually shutdown!). To stop mysql in safe mode I had to run this command: 'mysqladmin -u root -p shutdown'Mensal
great work, 3 hours later i'm glad i found this answer, installing mysql server is fun because stuff like makes you question your professionFennie
Indeed :D, I felt like quitting when I faced this for a week. I was just trying to store name and email in the user table.Swithbart
I see the following under journalctl -xn, it seems that the authentication plugin and password are mutually exclusive? "2019-05-07 14:06:14 9 [Warning] 'user' entry 'root@localhost' has both a password and an authentication plugin specified. The password will be ignored."Roscoeroscommon
H
60

You can try as follows it works for me.

Start server:

sudo service mysql start

Now, Go to sock folder:

cd /var/run

Back up the sock:

sudo cp -rp ./mysqld ./mysqld.bak

Stop server:

sudo service mysql stop

Restore the sock:

sudo mv ./mysqld.bak ./mysqld

Start mysqld_safe:

 sudo mysqld_safe --skip-grant-tables --skip-networking &

Init mysql shell:

 mysql -u root

Change password:

Hence, First choose the database

mysql> use mysql;

Now enter below two queries:

mysql> update user set authentication_string=password('123456') where user='root';
mysql> update user set plugin="mysql_native_password" where User='root'; 

Now, everything will be ok.

mysql> flush privileges;
mysql> quit;

For checking:

mysql -u root -p

done!

N.B, After login please change the password again from phpmyadmin

Now check hostname/phpmyadmin

Username: root

Password: 123456

For more details please check How to reset forgotten password phpmyadmin in Ubuntu

Houri answered 13/9, 2018 at 23:18 Comment(4)
only this works for me! backup and restore socket is pretty smartCutup
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) before the "done!" line in your answer when trying to login with 123456.Blondell
I solved doing the described steps in phpmyadmin (i.e. change password, change plugin). For some reason 'set authentication_string=password(...)' made it stop working (Error 1045 (28000): Access denied...).Eaglewood
Although this is a solution, whenever I restart my computer(ubuntu 20.04), I have to run all of these commands. Any permanent solution?Subnormal
G
28

The mysql command by default uses UNIX sockets to connect to MySQL.

If you're using MariaDB, you need to load the Unix Socket Authentication Plugin on the server side.

You can do it by editing the [mysqld] configuration like this:

[mysqld]
plugin-load-add = auth_socket.so

Depending on distribution, the config file is usually located at /etc/mysql/ or /usr/local/etc/mysql/

If unix_socket=OFF is set in the same section, enable it by changing it to unix_socket=ON or this fix does not apply.

Genova answered 7/1, 2019 at 10:11 Comment(3)
THIS one. All the other answers explain how to work around the error. This one explains how to RESOLVE it.Senghor
If you're on MariaDB 10.4.3 and later, the unix_socket auth plugin should be installed by default, but if you incorrectly reference it as plugin="auth_socket", instead of plugin="unix_socket" when updating your "user", you will receive this somewhat misleading message. My answer elaborates on how I messed this up.Reeducate
If you're not on Debian or Ubuntu you might need to still load the plugin. "In other systems, although the plugin's shared library is distributed with MariaDB by default as auth_socket.so, the plugin is not actually installed by MariaDB by default. There are two methods that can be used to install the plugin with MariaDB." [[mariadb.com/kb/en/authentication-plugin-unix-socket/]] So in my case I still needed to add the plugin for ManjaroBird
C
13

For Ubuntu 18.04 and mysql 5.7

  • step 1: sudo mkdir /var/run/mysqld;

    step 2: sudo chown mysql /var/run/mysqld

    step 3: sudo mysqld_safe --skip-grant-tables & quit (use quit if its stuck )

login to mysql without password

  • step 4: sudo mysql --user=root mysql

    step 5: SELECT user,authentication_string,plugin,host FROM mysql.user;

    step 6: ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root'

now login with

  • mysql -u root -p <root>
Chandra answered 7/1, 2019 at 15:10 Comment(1)
but at which step may i set the pass for root? because i tried $ mysql -u root -p but access denied yet. Access denied for user 'root'@'localhost' (using password: YES) I tried to input 'YES' passwordKeely
F
9

You can try these some steps:

Stop Mysql Service 1st sudo /etc/init.d/mysql stop

Login as root without password sudo mysqld_safe --skip-grant-tables &

After login mysql terminal you should need execute commands more:

use mysql;

UPDATE mysql.user SET authentication_string=PASSWORD('solutionclub3@*^G'), plugin='mysql_native_password' WHERE User='root';

flush privileges;

sudo mysqladmin -u root -p -S /var/run/mysqld/mysqld.sock shutdown

After you restart your mysql server If you still facing error you must visit : Reset MySQL 5.7 root password Ubuntu 16.04

Foment answered 21/3, 2018 at 8:21 Comment(0)
A
7

Try it:

sudo mysql_secure_installation

Work's in Ubuntu 18.04.

Anaheim answered 3/9, 2018 at 3:38 Comment(0)
R
6

In case someone lands here after making the same mistake I did:

  1. Switched to plugin="mysql_native_password" temporarily. Performed my tasks.
  2. Attempted to switch back to the "auth_socket" plugin, but incorrectly referenced it as plugin="auth_socket" which resulted in mysql "ERROR 1524 (HY000): Plugin 'auth_socket' is not loaded"
  3. Lacking a way to login to fix this mistake, I was forced to have to stop mysql and use mysql_safe to bypass authentication in order to switch to the appropriate plugin plugin="unix_socket"

Hopefully this saves someone some time if they receive the original poster's error message, but the true cause was flubbing the plugin name, not actually lacking the existence of the "auth_socket" plugin itself, which according to the MariaDB documentation:

In MariaDB 10.4.3 and later, the unix_socket authentication plugin is installed by default, and it is used by the 'root'@'localhost' user account by default.

Reeducate answered 15/9, 2019 at 4:6 Comment(0)
P
6

I tried with and it works

use mysql; # use mysql table
update user set authentication_string="" where User='root'; 

flush privileges;
quit;
Posset answered 30/9, 2020 at 22:40 Comment(1)
This worked for me on mysql version 8.0.22 for ubuntu 20.04+. This says PASSWORD() function is removed from mysql 8.0.Ames
P
1

It works for me (ubuntu 22.04):

1) stop and remove mysql and related services

sudo kill $(pgrep mysql)
sudo apt-get remove --purge mysql-\*
sudo rm -rf /etc/mysql

2) download APT repo https://dev.mysql.com/downloads/repo/apt/

3) follow guide https://dev.mysql.com/doc/mysql-apt-repo-quick-guide/en/

shortlist from the guide:

sudo dpkg -i mysql-apt-config_0.8.24-1_all.deb

inside the dialog leave settings as is

sudo apt-get update
sudo apt-get install mysql-server

it should be a dialog: set ROOT password and leave auth setting as is. I've tried to change it and got auth error.

Finally

sudo apt-get update
sudo apt-get install mysql-workbench-community

Hope it will save your time, good luck :)

Prole answered 6/1, 2023 at 15:55 Comment(0)
H
0

On macOS. If you don't use brew services, install it https://github.com/Homebrew/homebrew-services

Stop MySQL:

brew services stop [email protected]

Start MySQL in safe mode:

mysqld_safe --skip-grant-tables &

Login to MySQL:

mysql -u root

Use mysql table:

use mysql;

Update the authentication:

update user set authentication_string=PASSWORD('') where User='root';
update user set plugin='mysql_native_password' where User='root';

Flush the privileges and quit

flush privileges;
quit;

Restart MySQL:

/usr/local/opt/[email protected]/bin/mysql.server stop
brew services start [email protected]
Heedless answered 25/9, 2023 at 1:29 Comment(0)
H
-1

This may work

CREATE USER 'user'@'localhost' IDENTIFIED BY 'pwd';

ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

Hydrodynamic answered 23/2, 2021 at 6:24 Comment(0)
H
-1

My cmd prompt was displaying the same error and sql installation command was stuck. Below commands worked for me.

Open a new terminal. Terminate the current open mysql_secure_installation from first terminal,

sudo killall -9 mysql_secure_installation

Start the mysql client and you will move to sql prompt:

sudo mysql

Run the following SQL query:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'setYourPasswordHereWithinQuotes';

exit

Let's secure it by entering in cmd:

sudo mysql_secure_installation

Whenever promoted for password, use the setYourPasswordHereWithinQuotes password you set in above sql query.

DONE!

Hustle answered 15/12, 2022 at 8:11 Comment(1)
This worked for me, anyways.Hustle
C
-9

You can try with the below commands:

hduser@master:~$ sudo /etc/init.d/mysql stop
[ ok ] Stopping mysql (via systemctl): mysql.service.
hduser@master:~$ sudo /etc/init.d/mysql start
[ ok ] Starting mysql (via systemctl): mysql.service.
Christiechristin answered 9/5, 2019 at 12:34 Comment(1)
Can you explain that further? How does restarting the server solve the given error message?Horgan

© 2022 - 2024 — McMap. All rights reserved.