拒绝用户‘root’@‘localhost’访问(使用密码:是)

拒绝用户‘root’@‘localhost’访问(使用密码:是)

如何重置或删除或输入新密码或查看密码。如果仍然无法解决,如何删除所有 MySQL 依赖项并重新安装。我是 Linux 新手,这是我的个人电脑(笔记本电脑)。请查看我的终端的输出。

pra@pra-K55N:~$ sudo mysql
[sudo] password for pra: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
pra@pra-K55N:~$ sudo mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: 
Error: Access denied for user 'root'@'localhost' (using password: YES)
pra@pra-K55N:~$ sudo service mysql stop
pra@pra-K55N:~$ sudo mysqld_safe --skip-grant-tables &
[1] 2466
pra@pra-K55N:~$ 2019-11-15T14:56:08.897357Z mysqld_safe Logging to syslog.
2019-11-15T14:56:08.907624Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2019-11-15T14:56:08.915473Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.

[1]+  Exit 1                  sudo mysqld_safe --skip-grant-tables
pra@pra-K55N:~$ sudo mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
pra@pra-K55N:~$ sudo service mysql start
pra@pra-K55N:~$ sudo mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
pra@pra-K55N:~$ 

请参阅mysql.cnf

!包含目录 /etc/mysql/conf.d/ !包含目录 /etc/mysql/mysql.conf.d/

答案1

我建议通过运行带有选项--skip-grant-tables的服务器来重置root密码,此选项允许您无需密码即可使用sudo运行以下命令登录mysql:

# sudo service mysql stop

# sudo mysqld_safe --skip-grant-tables &

# sudo mysql -u root

mysql> use mysql;

mysql> update user set authentication_string=PASSWORD("YOUR-NEW-ROOT-PASSWORD") where User='root';

mysql> flush privileges;

mysql> quit

# sudo service mysql stop

# sudo service mysql start

# sudo mysql -u root -p

现在你可以用你的新密码登录 SQL

check may be it's possible to find a query file about root password in path /home/$USER/.mysql_history or /root/.mysql_history

Note: prior to MySQL 5.7 the column was called password instead of authentication_string. Replace the line above with

mysql> update user set password=PASSWORD("YOUR-NEW-ROOT-PASSWORD") where User='root';

祝你好运

相关内容