简体   繁体   中英

I can use my local tool connect the remote server's mysql using root account. But I can not in the remote server `mysql -u root -p xxx` to connect

I can use my local tool connect the remote server's mysql using root account. But I can not in the remote server mysql -u root -p xxx to connect.

# mysql -uroot -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

if I do not input the root account's password, I can login directly.

But I can not change anything, even can not choose a database:

mysql> use mysql;
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql' 

I also can not stop the mysql:

# /usr/bin/mysql stop 
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'stop'

Even I can not kill the process.

[root@w9 templates]# ps -ef | grep mysql
root     23112 31156  0 09:44 pts/1    00:00:00 grep --color=auto mysql
root     31453     1  0 7月02 ?       00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql
mysql    31660 31453  0 7月02 ?       00:19:05 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
[root@w9 templates]# ps -ef | grep mysql | grep -v grep
root     31453     1  0 7月02 ?       00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql
mysql    31660 31453  0 7月02 ?       00:19:05 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
[root@w9 templates]# kill -QUIT 31453
[root@w9 templates]# ps -ef | grep mysql | grep -v grep
root     31453     1  0 7月02 ?       00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql
mysql    31660 31453  0 7月02 ?       00:19:05 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
[root@w9 templates]# 

afterwards I kill -9 the mysql.


I don't know whether the issue is caused by my command:

use mysql;

update user set host = '%' where user ='root' and host='localhost';

As you said, you can force kill your mysql processes by kill -9 PID .

Then launch the mysql safe mode:

/usr/bin/mysqld_safe --skip-grant-tables

open another ssh connect.

in the new ssh connect:

# mysql
mysql>use mysql
mysql>update user set host = 'localhost' where user ='root' and host='%';
mysql>flush privileges;
mysql>exit

now you can kill the safe mode window:

pkill -KILL -t pts/1

and restart the mysql by service mysqld start , if there gets error related to mysql.sock , you can find those issue solution on SO, thats not related to this issue.

if is:

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

because is force kill the mysql, you can rm the /var/lib/mysql/mysql.sock , then start

if get this issue:

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

sudo setenforce 0 
service mysqld start

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM