MySQL忘记root密码--不重启mysqd重置root密码
先提个问题:如何不重启mysqld,且没有权限修改用户账号和权限的情况下,如何重新设置root密码?不知道没关系,在此之前我也是不知道如何操作的,先看看下面的几种重置root密码的方法。
1、skip-grant-tables
我们常用的方法是使用skip-grant-tables选项,mysqld server启动之后并不使用权限系统(privilege system)。用户不需要任何账号、不受任何限制的访问数据库中所有数据。为了安全起见,通常加上skip-networking,mysqld不侦听任何TCP/IP连接请求。操作过程如下,
1)修改my.cnf配置文件,在mysqld选项中添加skip-grant-tables和skip-networking。
2)再重启mysqld server。
3)通过sql语句修改mysql.user表中存储密码。执行flush privileges,重新启用mysql权限系统。
UPDATE mysql.user SET password=PASSWORD('newpwd')WHERE user='root';
FLUSH PRIVILEGES;
4)删除或者注释配置文件中skip-grant-tables和skip-networking的参数选项。如果使用skip-networking,则需要再次重启mysqld。因为skip-networking不是系统变量,只是mysqld的参数选项,而不能通过系统变量动态进行设置。如果没有适用skip-networking,只需要执行flush privileges就可以使权限系统重新生效。
2. --init-file
mysqld_safe可以使–init-file参数选项来执行重新设定密码的sql语句。
1)新建一个初始化文件,如/tmp/initfile,文件内容为上面修改密码的sql语句。
UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';
FLUSH PRIVILEGES;
2)关闭mysqld服务进程。
3)使用mysqld_safe启动mysqld;
mysqld_safe --init-file=/home/me/mysql-init &
上面的两种方法是在忘记root密码情况下重新设置密码的方法,可以发现都需要重启mysqld服务。很多人都是使用第一种进行重置root密码,但是比较推荐的做法反而是第二种,即安全有快捷简单。
3、不重启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 [root@localhost mysql]#
[root@localhost mysql]# kill -SIGHUP
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>
MySQL忘记root密码--不重启mysqd重置root密码的更多相关文章
- oracle忘记sys/system/scott用户密码了,如何重置oracle密码?
今天用到的oracle数据库,但是发现以前设置的密码,忘记了,怎么输入都不对,所以从网上找了一下资料,解决了,然后整理分享给大家. 一.遇到的问题: 1..忘记除SYS.SYSTEM用户之外的用户的登 ...
- 忘记dba用户密码,利用SQLPlus重置dba密码
打开SQL Plus 输入用户名: sys as sysdba 输入口令:可直接回车 连接到: Oracle Database 11g Enterprise Edition Release 11.2. ...
- MySQL 8 重置 root 密码
如果 root 密码丢失,如何重置 root 密码? 重置 root 密码:Unix 和 类 Unix 系统: 1.登录 Unix 系统用户(运行MySQL服务器的用户) 2.停止MySQL服务器 ...
- Mysql忘记密码,支持中文,tab补全
忘记Mysql密码: (1)暂停服务: /etc/init.d/mysqld stop (2)跳过grant表授权,进入安全模式,并在后台运行: mysqld_safe --skip-grant-ta ...
- mac下安装mysql 1820 重置默认密码
mac安装mysql时会给出一个临时密码 记录下来 2018-03-17T02:14:10.809431Z 1 [Note] A temporary password is generated for ...
- 【linux】切换到root用户,并重置root用户密码
1.切换当前用户 到 root用户 sudo -i 2.重置root用户密码 sudo passwd root
- mysql忘记密码如何重置密码,以及修改root密码的三种方法
1.先将MySQL停止. 命令:systemctl stop mysqld #停掉MySQL 命令:systemctl status mysqld #查看状态 2.然后跳 ...
- Ubuntu下MySQL忘记root密码重置
MySQL忘记root密码肿么办?-_-||| 这种情况虽然不是很常见,但是有时长时间没有登录系统,还真会忘记密码.这时候,如果您能以系统管理员权限登陆密码,那还是有救的.放大招,将其重置即可. ...
- mysql 忘记root密码,重置密码,及重置密码后权限问题不能登录的解决方案
由于一段时间没有使用MySQL,忘记了root登录密码. 决定重置下密码,搜索帮助. 参考文档: http://blog.csdn.net/odailidong/article/details/507 ...
随机推荐
- 使用UIScrollView 结合 UIImageView 实现图片循环滚动
场景: 在开发工作中,有时我们需要实现一组图片循环滚动的情况.当我们使用 UIScrollView 结合 UIImageView 来实现时,一般 UIImageView 会尽量考虑重用,下面例子是以( ...
- Ant 学习笔记
1.下载Ant 官方网站http://ant.apache.org/bindownload.cgi 下载最新版本 .zip archive: apache-ant-1.9.4-bin.zip [PG ...
- [Python] 05 - Load data from Files
文件读写 一.文件打开 传统方法 >>> f = open('data.txt', 'w') # Make a new file in output mode ('w' is wri ...
- akka pubsub example
测了一个小时的 Pubsub 模式,发现这个模式和自己预期的不太一样,具体表现在: 1. 当 subscriber 订阅了某个 topic 并附带 groupName 时,如果 publish 发布的 ...
- JS =>处理单击事件与拖动事件并存
使用click事件,很难确定在拖动开始和结束的时候触发,所以使用了onmouseup(释放鼠标的时候),释放鼠标的时候,即在拖动还未结束,但是准备处理的阶段,此时mouseButtonFlag按照逻辑 ...
- Android手机用KSWEB搭建Web服务器成功安装WordPress
之前部落分享的几个免费Web服务器软件都是用来安装在本地电脑上,搭建Apache.PhpMyAdmin.MySQL等网站运行环境,然后我们就可以在电脑上测试运行Wordpress.Discuz! 论坛 ...
- apache 设置环境变量
在apache设置环境变量有什么好处: 提高代码的可移植性,不用因为换服务器而改项目代码
- git rebase 操作撤销
git rebase可以更改提交历史,在不影响别人的情况下,能够重整git树. 但如果git rebase操作失误,却在push后才发现,怎么撤销rebase操作呢? 使用git reflog + g ...
- SparkContext.union 与 RDD.union
RDD.union,和SparkContext.union都可以将多个RDD聚合成一个UnionRDD. 但不同的是,RDD.union在每次操作时,会创建一个新的数据集合,生成新的RDD,新的RDD ...
- Docker容器集群管理之Swarm
Docker容器集群管理主流方案 Swarm Docker公司自研发的集群管理系统. Kubernetes Google开源的一个容器集群管理系统,用于自动化部署.扩展和管理容器应用.也称为K8S ...