IDO老徐,在深圳,某上市公司质量部负责人,干了十二年软件测试,公号"简尚" ,博客isTester.com ,关注「软件测试从业者综合能力提升」,微信957863300

Mysql忘记root密码了怎么办(完整步骤)

上一篇 / 下一篇  2020-11-14 13:39:39 / 个人分类:linux


5PM.o C:S"Ow0

前提,

;n;|;q)p7U;S8r.J0

能登录到mysql的这台Linux服务器 ;51Testing软件测试网C3`#v4fl7`1_:h o3t


3ab\6|+X4R0


51Testing软件测试网6vJ g4q O0Q8C {s

已经忘记了mysql root密码,无法登录的情况下,

#}0wk~5bg@0~.HV&R9k0

限于有权限修改mysql安装文件(此方法适用于linux 

ID|r:E \0R0


51Testing软件测试网3w bQ,?r&zj&vF


Linux为例: 51Testing软件测试网(}Q(Bt#tv7d[,V/f


!u*D2GY}O$W z%h0


51Testing软件测试网I4\p-X\tu&S

1.编辑/etc/my.cnf配置文件,vim /etc/my.cnf51Testing软件测试网k&hZ4S#ek;i2n7xk


51Testing软件测试网4`6nMMl nd


n5qE L'W0

2.在[mysqld]下添加一行 skip-grant-tables,然后保存并退出

X+K0z ?u/e1rAR)vO0


&L:~M)k;J L;O K0

[mysqld]51Testing软件测试网;~ oVzb:iE+@

#

M0[T8g n0

# Remove leading # and set to the amount of RAM for the most important data51Testing软件测试网X:wCMV&B4P!@g W9A

# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.

\eSrl'Y0

# innodb_buffer_pool_size = 128M

%Y-EW4P\ j*vK0

#

%J!J*F uN0

# Remove leading # to turn on a very important data integrity option: logging

F$e t'w3`0

# changes to the binary log between backups.

6SP7[3W3V0

# log_bin

`~%s1p/yK1`(I0

#51Testing软件测试网 S(H o,UOe n7nPq

# Remove leading # to set options mainly useful for reporting servers.51Testing软件测试网l Ty2Y7W"x.X}

# The server defaults are faster for transactions and fast SELECTs.

6A!S^DQj{3P2t0

# Adjust sizes as needed, experiment to find the optimal values.51Testing软件测试网 G F`y"VW!YkgV

# join_buffer_size = 128M

S t\ `qd~,Ft0

# sort_buffer_size = 2M

$iL V`%y-k,R{7F0

# read_rnd_buffer_size = 2M51Testing软件测试网Q9RUA6g0uI

datadir=/var/lib/mysql

'vE4n+er b0D0

socket=/var/lib/mysql/mysql.sock

8Q bz#U7U8nB U0


\xb:zZ%I/Q0

# Disabling symbolic-links is recommended to prevent assorted security risks51Testing软件测试网 {"r ? o(_ R4V

symbolic-links=051Testing软件测试网m7Q}k5gb!f4n'\


M`o/W,I)Njj0

log-error=/var/log/mysqld.log51Testing软件测试网%c4CC_5o1z:^X

pid-file=/var/run/mysqld/mysqld.pid

R3w7aeed9O)Va0


GN S/_ E%`i:O0


A9Y8R,FA7YYG0

# ADD free password by idoxu (isTester.com)

8G1g|JW"ab"R*hw0

skip-grant-tables      # IDO老徐注:新增这行

+l3{9RM/be*J.lZ GamPE0

                                                                                                                                     

)dgtw)XNN0

~                                                       51Testing软件测试网 t&q1Wnm@+F


51Testing软件测试网U;]h3LA

3.重启mysql服务:service mysqld restart51Testing软件测试网_0L%`(N1d$I

NP-@ ]:u5Lq0

[root@isTester ~]# service mysqld restart51Testing软件测试网*l2ULq v.o%[],oPG

Redirecting to /bin/systemctl restart mysqld.service51Testing软件测试网?ZrP"N \\[

[root@isTester ~]# 51Testing软件测试网|}p6a2p.q7g+U m8{

51Testing软件测试网HB5wIS!Z.z

,b,GF^}'gSw'Vs7_ h0


51Testing软件测试网e2g*CV C ^9cE,P r eP }


D5\ Xf(UZkPS+AN0

4.更改root密码51Testing软件测试网{h$~9@9y+e1\;O

重启以后,执行mysql命令进入mysql命令行(上面已经设置了跳过密码,不用输入密码)

G4X*Y1|"C~U0


51Testing软件测试网.} hv3Q~cb

[root@isTester ~]# mysql51Testing软件测试网ADt:A4d LUV/y:N6i

Welcome to the MySQL monitor.  Commands end with ; or \g.51Testing软件测试网%e%h#["~ `|4U6~"v

Your MySQL connection id is 2

C5N]i G)]h3}%j0

Server version: 5.7.30 MySQL Community Server (GPL)51Testing软件测试网\n`(X-t'i p-\


51Testing软件测试网x:?V C QD K"V

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.51Testing软件测试网{'A4ZPa2z2m


51Testing软件测试网 sK"H4lGK

Oracle is a registered trademark of Oracle Corporation and/or its

tV8qQH0

affiliates. Other names may be trademarks of their respective51Testing软件测试网X Zv1] T P+b-F;e!a

owners.

{MD)g4S6U0


51Testing软件测试网X vT%U$vj

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

UJ8qXX9_0


51Testing软件测试网^ PdH6EaY

mysql> 

X{N0f"N P,E0


-CK*~6jR\)wgZ4Q7x0


51Testing软件测试网qfVac1I._


51Testing软件测试网k5Y Y`&V d z.l|"r

5.修改root用户密码51Testing软件测试网+B Bps)q\ QL

参考文章51Testing软件测试网2|,t'XQ c^s*KP8B


51Testing软件测试网+B6H^0n+\ X7~


51Testing软件测试网%`;Kb|&h%D[

6./etc/my.cnf中的skip-grant-tables注释掉

7Nj6C!l6z@0


51Testing软件测试网4W2ct9D%gD/g2O

参考第2

/`+c*t N0b0

# ADD free password by idoxu (isTester.com)51Testing软件测试网"lTk};X {8gQ

# skip-grant-tables      # IDO老徐注:前面新增一个 # 注释掉这行51Testing软件测试网FJ4~1@ SWiv)~]

~     

wKRSQWOs0


w[4K h7lZx0


51Testing软件测试网S[SD&Ky:o1_

7.重启mysql51Testing软件测试网+Qu8@t9vq7q`

参考第351Testing软件测试网LA/j5a*Ci


(|`;R%s3_1m B0


51Testing软件测试网e*`\w r@7}

搞定,51Testing软件测试网cGU%A%K TO9^r

可以用root新的密码登录了

9~n(A3}:\ Y)q+F0

TAG:

 

评分:0

我来说两句

xuquan

xuquan

IDO老徐,坐标深圳,测试经理,干了十年测试,公号"简尚" ,个人博客isTester.com ,关注「软件测试从业者综合能力提升」,微信957863300

日历

« 2022-11-18  
  12345
6789101112
13141516171819
20212223242526
27282930   

数据统计

  • 访问量: 836545
  • 日志数: 427
  • 建立时间: 2012-06-04
  • 更新时间: 2022-02-23

RSS订阅

Open Toolbar