Reputation: 24280
My local environment is:
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.
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:
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.
Incorrect auth plugin
mysql "ERROR 1524 (HY000): Plugin 'unix_socket' is not loaded"
Here I stopped or somehow got to step 1. again.
Upvotes: 178
Views: 357151
Reputation: 85371
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 the distribution, the config file can be 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.
Upvotes: 30
Reputation: 1
ah, i encontered this today and stucked for soooo long time with all those method failed, on the circumstance when i was trying to migrant db from mysql to MariaDB. Here's how i solved it.
Fisrtly, it happened when you change any info and setting for any users succeeded from the old db, tunred out to be the different authenticating way between mysql and MariaDB.
So after the migration, you got the chance to login in without any change in user info and setting. Once you have imported you backup.sql from mysql to mariaDB, use your root accese to exert below:
USE mysql;
UPDATE mysql.user SET plugin = 'mysql_native_password';
then try to change the .cnf in the /etc/mysql/ which contains the "[mysqld]"
then under the [mysqld], add:
plugin-load-add = auth_socket.so
After all those operatons, this might be solved. Hope it work for U.
Upvotes: 0
Reputation: 47
I don't have enough reputation points to comment so I am posting here. +1 vote for @Gorcer's answer about mysql_secure_installation. If you haven't run secure installation on the server (as I hadn't), run that first. It will enable auth_socket. It worked for me on Ubuntu 22.04 LTS.
Upvotes: 0
Reputation: 41
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]
Upvotes: 0
Reputation: 11
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 :)
Upvotes: 1
Reputation: 133
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!
Upvotes: -1
Reputation: 24280
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!
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
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;
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
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)
mysql -uroot # "-hlocalhost" is default
Can lead to "missing file" or slt error.
mysql -uroot -h127.0.0.1
Works better.
I've found many ways to create mysqld.sock
file, change access rights, or symlink it. It was not the issue after all.
my.cnf
fileThe issue also was not there. If you are not sure, this might help you.
Upvotes: 461
Reputation: 39
This may work
CREATE USER 'user'@'localhost' IDENTIFIED BY 'pwd';
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
Upvotes: -1
Reputation: 104
I tried with and it works
use mysql; # use mysql table
update user set authentication_string="" where User='root';
flush privileges;
quit;
Upvotes: 6
Reputation: 391
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>
Upvotes: 13
Reputation: 838
In case someone lands here after making the same mistake I did:
plugin="mysql_native_password"
temporarily. Performed my tasks.plugin="auth_socket"
which resulted in mysql "ERROR 1524 (HY000): Plugin 'auth_socket' is not loaded"
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.
Upvotes: 6
Reputation: 1
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.
Upvotes: -9
Reputation: 5020
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
Upvotes: 61
Reputation: 101
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
Upvotes: 9