用户工具

站点工具


zh:notes:centos_mysql_pwd

这是本文档旧的修订版!


Reset the Password of MySQL in the CentOS

Stop mysql

> systemctl stop mysqld

Set the MySQL environment Option

> systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"

Start mysql

> mysql -uroot

Update the Password

mysql> USE mysql
mysql> ALTER USER "root"@"localhost" IDENTIFIED BY "MyNewPassword";
mysql> FLUSH PRIVILEGES;
mysql> quit

Stop mysql

> systemctl stop mysqld

Unset the MySQL Environment Option

> systemctl unset-environment MYSQLD_OPTS

Start mysql

> systemctl start mysqld

重新启动mysqld

# service mysqld restart

登录并修改MySQL的root密码

# mysql 
mysql> USE mysql ; 
mysql> UPDATE user SET Password = password ( 'new-password' ) WHERE User = 'root' ; 
mysql> flush privileges ; 
mysql> quit

将MySQL的登录设置修改回来

# vim /etc/my.cnf 

将刚才在[mysqld]的段中加上的skip-grant-tables删除 保存并且退出vim

重新启动mysqld

# service mysqld restart 
zh/notes/centos_mysql_pwd.1666442562.txt.gz · 最后更改: 2022/10/22 20:42 由 pzczxs