(相干引荐:MySQL教程)
步骤1:在平安形式下启动MySQL
起首,须要住手运转mysql效劳器。我们运用以下敕令之一在Linux体系上住手MySQL效劳器。
# service mysql stop //关于基于SysVinit的体系 # systemctl stop mysql.service //关于基于Systemd的体系
如今在平安形式下运用--skip grant tables选项启动mysql效劳器。运用以下敕令以平安形式启动MySQL。在平安形式下,MySQL不提醒输入登录暗码。
# mysqld_safe --skip-grant-tables &
步骤2:重置mysql root暗码
如今以root用户身份登录到mysql效劳器,并运用以下敕令变动暗码。这将重置体系上的mysql root暗码。
关于MySQL5.6或更低版本
# mysql -u root mysql>USE mysql; mysql>UPDATE user SET password=PASSWORD("NEW-PASSWORD") WHERE User='root'; mysql>FLUSH PRIVILEGES; mysql>quit
关于MySQL5.7或更高版本
# mysql -u root mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD("NEW-PASSWORD"); mysql>FLUSH PRIVILEGES; mysql>quit
步骤3:重启mysql效劳器
变动暗码后,住手mysql(在平安形式下运转)效劳,并运用下面的敕令从新启动它。
//基于SysVinit的体系 # service mysql stop # service mysql start //基于Systemd的体系 # systemctl stop mysql.service # systemctl start mysql.service
步骤4:考证新暗码
从新设置mysql root账号暗码并重启后,只需登录考证新暗码即可。
# mysql -u root -p Enter password: ********** Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 29 Server version: 5.5.57 MySQL Community Server (GPL) Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
本篇文章到这里就已悉数完毕了,更多精彩内容人人能够关注ki4网的其他相干栏目教程!!!
以上就是怎样在Linux中重置MySQL root暗码的细致内容,更多请关注ki4网别的相干文章!