尝试更改 mysql root 密码时卡住了

尝试更改 mysql root 密码时卡住了

我已经查找了如何在线更改 root 密码,他们总是告诉我这样做,sudo mysqld_safe --skip-grant-tables &当我运行它时,它除了输出以下内容外什么也不做:

matthew@matthewserver:~$ sudo mysqld_safe --skip-grant-tables &
[1] 24648
matthew@matthewserver:~$ 2018-10-03T20:44:58.008288Z mysqld_safe Logging to syslog.
2018-10-03T20:44:58.013391Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2018-10-03T20:44:58.041802Z mysqld_safe A mysqld process already exists

我已经启动了 mysql。但是我可以执行 sudo mysql。当我执行 sudo mysql 时,我运行了这个ALTER USER 'root'@'localhost' IDENTIFIED BY '******';,但是当我尝试登录时,它只输出:

matthew@matthewserver:~$ mysql -u root -p
Enter password:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

答案1

讯息

mysqld 进程已存在

很清楚:您需要在运行此操作之前停止 MySQL,因为 MySQL 不能在同一系统上运行多次。如何执行此操作取决于您的环境,您不会告诉我们有关环境的信息。

答案2

要更改 mysql 根密码,我建议按照以下步骤操作:

1-停止 mysqld 实例

sudo /etc/init.d/mysqld stop

2 - 无需密码启动 MySQL

sudo mysqld_safe --skip-grant-tables &

3 - 以 root 身份连接并更改其密码

mysql -uroot
use mysql;
update user set password=PASSWORD("mynewpassword") where User='root';
flush privileges;
quit

4 - 重新启动 mysqld 实例

sudo /etc/init.d/mysqld restart

相关内容