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 ...
随机推荐
- Python套接字编程(1)——socket模块与套接字编程
在Python网络编程系列,我们主要学习以下内容: 1. socket模块与基本套接字编程 2. socket模块的其他网络编程功能 3. SocketServer模块与简单并发服务器 4. 异步编程 ...
- PHP最全笔记(四)(值得收藏,不时翻看一下)
// 序列化(串行化) # 数据传输均是字符串类型 # 除了资源类型,均可序列化 # 序列化在存放数据时,存放数据本身,也存放数据类型 1.在网络传输数据时:2.为了将数组或对象放在磁盘时 # 序列化 ...
- Generate class from database table How can i generate a class from a table at a SQL Server?
Set @TableName to the name of your table. declare @TableName sysname = 'TableName' declare @Result v ...
- ABBYY FineReader 12如何识别包含非常规符号的文本
ABBYY FineReader 12 是一款OCR图文识别软件,可快速方便地将扫描纸质文档.PDF文件和数码相机的图像转换成可编辑.可搜索的文本,有时文本中可能会包含一些非常规的符号,此时ABBYY ...
- [Optimization] Greedy method
Given two sequences of letters A and B, find if B is a subsequence of A in thesense that one can del ...
- [Laravel] 15 - REST API: sidebar with unit test
前言 实现一个博客的侧边栏的链接,然后顺便对其进行单元测试的过程. Archives 一.视图中展示SQL结果 一条 sql 语句[查询] select year(created_at) year, ...
- ef 某些字段更新 某些字段不更新
不更新 _pocDbContext.Entry<UploadFileActiveTask>(activeTask).Property("id").IsModified ...
- 条件变脸pthread_cond_signal丢失问题
直接上代码: static bsem_t bsem; void* t1(void *arg) { /*printf("enter task 1\n");*/ /*while(1)* ...
- git合并分支上指定的commit
merge 能够胜任平常大部分的合并需求.但也会遇到某些特殊的情况,例如正在开发一个新的功能,线上说有一个紧急的bug要修复.bug修好了但并不像把仍在开发的新功能代码也提交到线上去.这时候也许想要一 ...
- B - Pie
My birthday is coming up and traditionally I'm serving pie. Not just one pie, no, I have a number N ...