MySQL忘记root密码--不重启mysqd重置root密码

找回丢失mysql root密码

一、启动修改丢失的mysql单实例root密码方法;

1.首先停止mysql


/etc/init.d/mysql stop

2.使用--skip-grant-tables启动mysql,忽略授权登录验证


mysqld_safe --skip-grant-tables --user=mysql & --提示:在启动时加--skip-grant-tables 参数,表示忽略授权验证

3.进入数据库系统


shell>mysql

4.修改mysqlroot密码:update


mysql>update mysql.user set password=password("123456") where user='root' and host='localhost';

mysql>flush privileges;

shell>mysqladmin -uroot -p123456 shutdown

5.重新启动mysql


shell>/etc/init.d/mysql start

shell>mysql -uroot -p123456

二、多实例丢失密码的方法:

1.关闭mysql


mysqld_mulit stop

2.启动时加--skip-grant-tables参数


mysqld_safe --defaults-files=/data/mysql/mysql3377/mysql3377.cnf --skip-grant-tables &

mysql -uroot -p -S /tmp/mysql3377.sock <==登录时空密码

3.修改密码方法:


update mysql.user set password=password("123456") where user='root'

flush privileges;

4.重启服务用新密码登录:


killall mysqld

mysqld_mulit restart 3377

三、不重启mysqld的方法

1、首先得有一个可以拥有修改权限的mysql数据库账号,当前的mysql实例账号(较低权限的账号,比如可以修改test数据库)或者其他相同版本实例的账号。把data/mysql目录下面的user表相关的文件复制到data/test目录下面。

[root@localhost mysql]# cp mysql/user.* test/
[root@localhost mysql]# chown mysql.mysql test/user.*

2、使用另一个较低权限的账号链接数据库,设置test数据库中的user存储的密码数据。

[root@localhost mysql]# mysql -utest -p12345
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 5.5.25a-log Source distribution

Copyright (c) 2000, 2011, 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> use test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set password=password('yayun') where user='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 5  Changed: 0  Warnings: 0

mysql>

3、把修改后的user.MYD和user.MYI复制到mysql目录下,记得备份之前的文件。

mv mysql/user.MYD mysql/user.MYD.bak
mv mysql/user.MYI mysql/user.MYI.bak
cp test/user.MY* mysql/chown mysql.mysql mysql/user.*

4、查找mysql进程号,并且发送SIGHUP信号,重新加载权限表。

[root@localhost mysql]# pgrep -n mysql
2184
[root@localhost mysql]#
[root@localhost mysql]# kill -SIGHUP 2184

5.登陆测试

[root@localhost mysql]# mysql -uroot -pyayun
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 20
Server version: 5.5.25a-log Source distribution

Copyright (c) 2000, 2011, 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>
时间: 2024-08-04 12:02:50

MySQL忘记root密码--不重启mysqd重置root密码的相关文章

MySQL 修改用户密码及重置root密码

    为数据库用户修改密码是DBA比较常见的工作之一.对于MySQL用户账户的密码修改,有几种不同的方式,推荐的方式使用加密函数来修改密码.本文主要描述了通过几种不同的方式来修改用户密码以及mysql root账户密码丢失(重置root密码)的处理方法.   1.密码修改的几种方法 a.可以在创建用户的时候指定密码,以及直接使用grant创建用户的时候指定密码. 对于已经存在的用户直接使用grant方式也可以修改密码 如下: --演示版本 root@localhost[(none)]> sho

Directadmin面板查看/重置管理密码

今天安装的时候,SSH自动断开了没有看到密码. 所以如何查看/重置管理员密码信息的呢.可以在SSH中直接查看安装日志 安装日志 cat /usr/local/directadmin/scripts/setup.txt admin账号的密码和mysql的管理员账号和密码在上面文件中查看到. 重置密码 如果你有修改admin的密码.可以选择使用重置命令 passwd admin 然后输入自己需要重置的密码即可.

Mysql忘记root密码怎么办_Mysql

MySQL有时候忘记了root密码是一件伤感的事,这种情况下,如何重置root的密码呢? 找到并编辑mysql的my.ini配置文件,在mysqld节点中添加上skip-grant-table. 如下: # These let you safely reset the lost root password. skip-grant-table 保存好修改,重启mysql服务. 现在就能不需要root密码的情况下连接上数据库.然后执行下面的更新: USE mysql; UPDATE USER SET

mysql忘记root密码的恢复方法

mysql的root忘记,现无法操作数据库 停止mysql服务service  mysql stop 或者是ps -ef |grep mysql|xargs kill -9 然后使用如下的参数启动mysql, --skip-grant-tables会跳过mysql的授权 shell#/usr/bin/mysqld_safe --skip-grant-tables & mysql -p  回车,进入不需要密码 mysql> mysql>update mysql.user set Pass

mysql 忘记root密码解决方案

虽然说做运维或其他人员对于数据库的账户维护是一件严肃的事情,但是难免会出现有些傻瓜蛋子会忘记密码的事情,这边总结一些忘记MySQL密码后的操作,来重新定义root密码 1.停止当前运行的数据库 /etc/init.d/mysqld stop 2.编辑 my.cnf 文档,并跳过权限表 vim /etc/my.cnf,并在[mysqld]中添加一条: skip-grant-tables 3.重启数据库并修改root密码 /etc/init.d/mysqld restart mysql -uroot

windows环境中mysql忘记root密码的解决方法详解_Mysql

一朋友告急:mysql 忘记root密码了 让我帮忙给看看,因为没有接触过mysql 所以从网上找了一下信息经我亲身实践  已经成功!mysql版本是5.1.以下是从网上找的mysql密码修改的信息:参考文章:windows下重置Mysql Root密码的方法mysql修改密码以及忘记密码1. 首先检查mysql服务是否启动,若已启动则先将其停止服务,可在开始菜单的运行,使用命令:net stop mysql 打开第一个cmd1窗口,切换到mysql的bin目录,运行命令:mysqld --de

MySQL密码忘了怎么办?MySQL重置root密码方法_Mysql

MySQL有时候忘记了root密码是一件伤感的事.这里提供Windows 和 Linux 下的密码重置方法. Windows: 1.以系统管理员身份登陆系统. 2.打开cmd-----net start 查看mysql是否启动.启动的话就停止net stop mysql. 3.我的mysql安装在d:\usr\local\mysql4\bin下. 4.跳过权限检查启动mysql. d:\usr\local\mysql\bin\mysqld-nt --skip-grant-tables 5.重新打

MAC上Mysql忘记Root密码或权限错误的快速解决方案_Mysql

最近一段时间都在倒腾mantis发现总是连接mysql出错,就随手修改了root权限,导致登录不上了. 下面给大家分享还原root权限和更改root密码的最便捷方法. 1:装mysql workbench .可视化界面直接操作. 2:苹果->系统偏好设置->最下边点mysql 在弹出页面中 关闭mysql服务 3:进入终端 输入: cd /usr/local/mysql/bin/ 回车后 登录管理员权限 sudo su 回车后输入以下命令来禁止mysql验证功能 ./mysqld_safe -

Linux使用MySQL忘记root密码及修改MySQL默认编码_Linux

概述: 本文不再对MySQL的语法进行讲解和说明,想了解或熟悉的朋友请自行百度或Google学习.本文主要是针对MySQL除语法之外的总结,希望能够也能帮助到你. 1.CentOS6.x下MySQL忘记root密码解决方法 Ⅰ. 修改MySQL的登录设置  # vim /etc/my.cnf 在[mysqld]段中加上一句:skip-grant-tables Ⅱ. 重启服务 # service mysqld restart Ⅲ. 登录Mysql,修改密码信息# mysql mysql> USE