(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. 【由VerySky原创】由Number Range 导致凭证生成但无法保存的问题

    工厂正常生产,但某天突然发生车辆下线失败销售入库报错( MFBF凭证不能保存\ 下线车无法产生131 )的问题: ST22发现程序dump信息 分析 | SAPSQL_ARRAY_INSERT_DUP ...

  2. 服务器跟VPS有什么区别

    你好. 服务器是独立的真实存在的硬件设备.其实也就是一台高端电脑.他是放在机房运行的.主要为网站以及一些软件应用提供运行平台.而VPS是虚拟服务器.他是利用软件在服务器上虚拟出来的.也就是分配出一部分 ...

  3. SQL Server复制入门(一)----复制简介

    简介 SQL Server中的复制(Replication)是SQL Server高可用性的核心功能之一,在我看来,复制指的并不仅仅是一项技术,而是一些列技术的集合,包括从存储转发数据到同步数据到维护 ...

  4. Java SimpleDateFormat[转]

    [补充] [转] http://stackoverflow.com/questions/2603638/why-cant-this-simpledateformat-parse-this-date-s ...

  5. Apache Storm 的历史及经验教训——Nathan Marz【翻译】

    英文原文地址 中英文对照地址 History of Apache Storm and lessons learned --项目创建者 Nathan Marz Apache Storm 最近成为了ASF ...

  6. jackson json转实体 允许特殊字符和转义字符 单引号

    //允许出现特殊字符和转义符 mapper.configure(Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true) ; //允许出现单引号 mapper.confi ...

  7. 将json转换成struts参数

    加入对象为{name:'tom','class':{className:'class1'},classMates:[{name:'lily'}]}struts2期待的格式是 name=tom& ...

  8. 对list集合中的对象按照对象的某一属性进行排序

    /**  * 重新对list中的CmsCyUser对象按照最终的票数进行排序  * @param list  */ private void reSort(List list) {   Object[ ...

  9. Navi.Soft30.框架.WinForm.开发手册

    阅读导航 Navi.Soft30.Core类库.开发手册 http://www.cnblogs.com/xiyang1011/p/5709489.html Navi.Soft30.框架.WinForm ...

  10. Xcode真机调试中"There was an internal API error"错误解决方法

    xcode7更新之后使用真机调试,在IOS8的一台iphone6也没问题.IOS9.2的一台iphone6s也没问题.但是在IOS7.0的一台iPhone4s上面在最后安装的时候居然安装失败,提示 T ...