(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. Windows系统补丁KB2962872导致InstallShield无法启动(解决方案已更新)

    20140717最新更新: Flexera Software发布了临时补丁包,该补丁包暂时禁止了InstallShield Trialware功能(中国区用户很少有用此功能)两种安装方法: 方法1. ...

  2. ES5 数组方法every和some

    Array.prototype.every() 概述 every() 方法测试数组的所有元素是否都通过了指定函数的测试. 语法 arr.every(callback[, thisArg]) 参数 ca ...

  3. GTD时间管理---非行动性

    一:行动性和非行动有什么区别? 1:非行动性:指的是收集箱中的信息,是先存储后使用,这些信息平时都处于冬眠状态,只是要用到的时候能够找到它就好了.(偏向于处理生活) 2:行动性: 指的是收集箱中的信息 ...

  4. CSS计数器的趣味时光

    CSS计数器是“啊太好了,竟不知道CSS可以做这啊”这类非常有趣的众多特性之一.简言之,用CSS使你持续某增加某个量,而无需JavaScript. 简单计数器 我们从这个简单的分页示例开始: 你见到的 ...

  5. Python的列表推导式

    1.列表推导式书写形式: [表达式 for 变量 in 列表]    或者  [表达式 for 变量 in 列表 if 条件] 2.举例说明: #!/usr/bin/python # -*- codi ...

  6. myeclipse9或myeclipse10安装svn的方法

    下载最新的SVN包   site-1.6.5.zip 从中解压出features与plugins文件夹,复制到C:\toBeInstalledSVN 里面,其它的*.xml文件不要 复制下列java代 ...

  7. c++算法应用 预备

    章 C + +程序设计 大家好!现在我们将要开始一个穿越" 数据结构.算法和程序" 这个抽象世界的特殊旅程,以解决现实生活中的许多难题.在程序开发过程中通常需要做到如下两点:一是高 ...

  8. EZGUI下的动态图片的处理

    EZGUI的使用过程中,有时需要使用动态的图片,比如商店里面商品的ICON,好友的头像等,通过使用SimpleSprite可以实现这个功能.   比如一个通过网络显示好友头像: WWW www = n ...

  9. CHECK MEMBER TYPE

    检查类里是否存在某种类型的几种方法,以检查xxx类型为例:方法1: template<class T> class has_member_type_Type { ]; }; templat ...

  10. Cubieboard2裸机开发之(四)定时器操作

    前言 在Cubieboard2裸机开发之(三)里用到了一个延时函数delay,它的延时时间是不精确的,因此为了能够精确延时,就需要定时器的配合.定时器可以精确延时的一个重要原因是它的计时时钟(或者说频 ...