(1)登录到数据库所在服务器,手工kill掉MySQL进程:

kill ' cat /mysql-data-directory/hostname.pid'
    其中,/mysql-data-directory/hostname.pid指的是MySQL数据目录下的.pid文件,它记录了MySQL服务的进程号。
    (2)使用--skip-grant-tables选项重启MySQL服务:
[root@iZ28dr6w0qvZ mysql]# ./bin/mysqld_safe --skip-grant-tables --user=root &
[1] 17299
[root@iZ28dr6w0qvZ mysql]# 151006 13:14:41 mysqld_safe Logging to '/alidata/log/mysql/error.log'.
151006 13:14:41 mysqld_safe Starting mysqld daemon with databases from /alidata/server/mysql/data
    其中--skip-grant-tables选项的意思是启动MySQL服务的时候跳过权限表认证。启动后,连接到MySQL的root将不需要命令。
    (3)用空密码的root用户连接到MySQ,并且更新root口令:
[root@iZ28dr6w0qvZ ~]# mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.37-log MySQL Community Server (GPL) Copyright (c) 2000, 2014, 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> set password = password('ysj123');
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql> update mysql.user set password=password('123456') where user='root' and host='localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
    此时,由于使用了--skip-grant-tables选项启动,使用“set password”命令更改密码失败,直接更新user表的password字段后更改密码成功。
    (4)刷新权限表,使得权限认证重新生效:
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
    (5)重新用root登录时,必须输入新口令:
[root@iZ28dr6w0qvZ ~]# mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@iZ28dr6w0qvZ ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.5.37-log MySQL Community Server (GPL) Copyright (c) 2000, 2014, 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中,密码丢失后无法找回,只能通过上述方式修改密码。
 
别忘了给个赞哦!~

MySQL忘记root密码的找回方法的更多相关文章

  1. mysql忘记root密码的解决方法

    Windows下mysql忘记root密码的解决方法 1. 首先检查mysql服务是否启动,若已启动则先将其停止服务,可在开始菜单的运行,使用命令:net stop mysql 或者在windows任 ...

  2. 【转】mysql忘记root密码的解决方法

    本文收集于本人的笔记本,由于找不到原文出处.在此省略,如哪位知道可以联系我加上. 方法一:在windows下:1.打开命令行(DOS)窗口,停止mysql服务: net stop mysql 2.在D ...

  3. windows下的mysql忘记root密码的解决方法

    1.首先,需要关闭MySQL Server服务.在"运行"窗口,输入"services.msc",进入"服务"窗口. 2. 在服务窗口,可以 ...

  4. mysql忘记root密码的处理方法

    在linux下,如果忘记了mysql中root用户的密码可以采用以下办法解决. 1. 修改my.cnf,加入skip-grant-tables 修改mysql的配置文件my.cnf,在[mysqld] ...

  5. Windows下mysql忘记root密码的解决方法

    1. 首先检查mysql服务是否启动,若已启动则先将其停止服务,可在开始菜单的运行,使用命令: net stop mysql 打开第一个cmd窗口,切换到mysql的bin目录,运行命令: mysql ...

  6. 关于Windows下mysql忘记root密码的解决方法

    原文链接: http://www.cnblogs.com/andy_tigger/archive/2012/04/12/2443652.html 1. 首先检查mysql服务是否启动,若已启动则先将其 ...

  7. CentOS7下mysql忘记root密码的处理方法

    1.  vi /etc/my.cnf,在[mysqld]中添加 skip-grant-tables 例如: [mysqld] skip-grant-tables datadir=/var/lib/my ...

  8. mysql 忘记root 密码的解决方法

    LINUX 1.切换root 用户 2.停止mysqld 服务 /etc/inid.d mysqld stop 3.跳过验证登录 mysqld_safe --skip-grant-tables &am ...

  9. Mac mysql 忘记root密码的解决方法

    1.执行命令以安全模式启动MySQL cd /usr/local/mysql/bin sudo ./mysqld_safe --skip-grant-tables 2.同上面目录下执行 '\) whe ...

随机推荐

  1. 【OpenWRT】 Chaos Calmer 15.05 编译

    进入正题,编译环境准备完毕后,下载源码 git clone git://git.coding.net/leop/openwrt.git 复制代码 复制dl包(可以加快初次编译速度,但非必须)链接:pa ...

  2. 结合Domino打造全功能的Grid

    1.       需求说明: 在domino开发中我们经常会遇到表单上需要一个类似table的组件,你可以增删改等.比如我有一个张报核单据,上面需要详细列出每项金额的明细,我们先看完成后的效果: 上面 ...

  3. [leetcode]Find Minimum in Rotated Sorted Array II @ Python

    原题地址:https://oj.leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/ 解题思路:这道题和上一道题的区别是,数组中 ...

  4. LogViewer - 方便的日志查看工具

    一个完整的程序日志记录功能是必不可少的,通过日志我们可以了解程序运行详情.错误信息等,以便更好的发现及解决问题. 日志可以记录到数据库.日志服务器.文件等地方,本文主要介绍文件日志. 文件日志通常是一 ...

  5. Hbase&Hadoop常用命令

    Hbase中根据Rowkey的前缀Prefix查询数据: scan 'test_xiaomifeng_monitoring_log',{FILTER => "(PrefixFilter ...

  6. fresco Bitmap too large to be uploaded into a texture

    fresco加载图片方法 布局文件引入 xmlns:fresco="http://schemas.android.com/apk/res-auto" <com.faceboo ...

  7. 博为iHospital-HIS医院信息系统产品系列

    博为软件iHospital-HIS产品系列式面向大中型医院应用的完整医院流程信息化产品,覆盖了医院主要的业务流程,管理职能,和病人在医院诊疗的各个环节.将医院流程的优化与软件系统完美结合,为建立数字化 ...

  8. WinForm数据源分页技术

    1.编写分页存储过程 USE [Contacts]GO create procedure [dbo].[GetPageData] (@startIndex int,@endIndex int)asbe ...

  9. 所有文章都迁移到我自己的博客了:http://blog.neazor.com

    @import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...

  10. 删除.gitignore中的在version control中的文件

    如果有一个文件例如xyz在版本控制系统中,然后你发现这个文件不应该提交到git上,所以加了.gitignore文件并将其加入其中,但是git不会自动讲其从版本库中移除它.如果你只有一个文件,你可以使用 ...