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 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 1) again.
I got a solution!
When resetting root password at step 2), also change the auth plugin to
mysql_native_password
:This allowed me to log in successfully!
Full code solution
1. run bash commands
1. first, run these bash commands
2. then run mysql commands => copy paste this to cli manually
3. run more bash commands
4. Socket issue (from your comments)
When you see a socket error, a community came with 2 possible solutions:
(thanks to @Cerin)
Or
(thanks to @Peter Dvukhrechensky)
Blind paths and possible edge errors
Use 127.0.0.1 instead of localhost
Can lead to "missing file" or slt error.
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
fileThe issue also was not there. If you are not sure, this might help you.
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:
After you restart your mysql server If you still facing error you must visit : Reset MySQL 5.7 root password Ubuntu 16.04
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 inmysql "ERROR 1524 (HY000): Plugin 'auth_socket' is not loaded"
mysql_safe
to bypass authentication in order to switch to the appropriate pluginplugin="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:
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
You can try as follows it works for me.
Start server:
Now, Go to sock folder:
Back up the sock:
Stop server:
Restore the sock:
Start mysqld_safe:
Init mysql shell:
Change password:
Hence, First choose the database
Now enter below two queries:
Now, everything will be ok.
For checking:
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
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:Depending on distribution, the config file is usually located at
/etc/mysql/
or/usr/local/etc/mysql/