您好,欢迎访问一九零五行业门户网

如何在Linux中重置MySQL root密码

mysql是一种广泛用于数据存储的开源数据库软件。有时我们忘记了mysql root密码,但是不需要紧张,本篇文章将介绍关于如何通过简单的步骤重置mysql root密码。
(相关推荐: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 rootmysql> 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 -penter password: **********welcome to the mysql monitor. commands end with ; or \g.your mysql connection id is 29server 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 itsaffiliates. other names may be trademarks of their respectiveowners.type 'help;' or '\h' for help. type '\c' to clear the current input statement.mysql>
本篇文章到这里就已经全部结束了,更多精彩内容大家可以关注的其他相关栏目教程!!!
以上就是如何在linux中重置mysql root密码的详细内容。
其它类似信息

推荐信息