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

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

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


+TBTl#^0

前提,

pNp|H0

能登录到mysql的这台Linux服务器 ;

t i] cU;cGB0


2_&O'SV4|,D n0


51Testing软件测试网 i5o|p3T%w n2e

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

5U7vI g7__0

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

9z8p%iy:X&|FQP[ g|0


D!y G;O8Wbok$W0


Linux为例: 

2{MN8r };s0


`C,A2YAfN1r0


51Testing软件测试网7[ wCok}Y

1.编辑/etc/my.cnf配置文件,vim /etc/my.cnf51Testing软件测试网 w:A,p'Gop


51Testing软件测试网1[r_ Ud7L@c2l


51Testing软件测试网[T'Nukt-skO

2.在[mysqld]下添加一行 skip-grant-tables,然后保存并退出51Testing软件测试网c;}/Dp#_ U


51Testing软件测试网^W/]9c3CL0^F

[mysqld]

U-z;v[vf.ig(Jk0

#51Testing软件测试网h~c$b.]

# Remove leading # and set to the amount of RAM for the most important data

\t:Eu$k9[ ~3t0

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

oF9Kv'X#]Y9M0

# innodb_buffer_pool_size = 128M51Testing软件测试网9TnN"I$B)a

#

%Ie8^ xS v r0

# Remove leading # to turn on a very important data integrity option: logging51Testing软件测试网'z8^Msv:Y9f9HI

# changes to the binary log between backups.51Testing软件测试网5m,kD0aMd s0E

# log_bin

?JCM&I0

#51Testing软件测试网~4g7OlWw,jk

# Remove leading # to set options mainly useful for reporting servers.51Testing软件测试网] K-MW5^3lm7zH

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

#\x&vGI v4t0

# Adjust sizes as needed, experiment to find the optimal values.

fO [ }1Z)B-\qt f0

# join_buffer_size = 128M

I,t4e,^(]c.j0

# sort_buffer_size = 2M

b(R)UT T ^ODL0

# read_rnd_buffer_size = 2M

xZ;Tv/]0

datadir=/var/lib/mysql

dH;n-|q,xs~0

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

hi~ ^4A&T0


t8BS3S@!`'g)O#d0

# Disabling symbolic-links is recommended to prevent assorted security risks

A(n&b/Z)[Y7?*HT,{*i0

symbolic-links=0

8]jO2kHib'tfq\0


E9z7y-{+E)r"e0

log-error=/var/log/mysqld.log

*E/_(wj$T/[ aa0

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

6v.LL#w6}x0


.N K[ PhP6|M0


51Testing软件测试网}7K;]0il7F-\

# ADD free password by idoxu (isTester.com)51Testing软件测试网BRZ0Z+IH;m,Z:x

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

@K9_$L"u3rT{`0V0

                                                                                                                                     

dBn q N7~0[8S^3h0

~                                                       51Testing软件测试网dU_D W%vu


51Testing软件测试网j(fH'Zp2O0U7b/TR:p

3.重启mysql服务:service mysqld restart

AJp9e@fVsD,c{0

4n5n!c E ki A0

[root@isTester ~]# service mysqld restart51Testing软件测试网 N5E Nvz2FJ

Redirecting to /bin/systemctl restart mysqld.service51Testing软件测试网3hm3X L2\

[root@isTester ~]# 

h'R#Bw w5bo*U6V#NP5q0

i1{sF P"Q4sd T B0

51Testing软件测试网g+a4qsdz


51Testing软件测试网h%g cd|uSd


51Testing软件测试网#q^6C]v3R'd]

4.更改root密码51Testing软件测试网oDXK2ddE;B

重启以后,执行mysql命令进入mysql命令行(上面已经设置了跳过密码,不用输入密码)51Testing软件测试网,o V/|u2`A1z&rB


51Testing软件测试网u&Lo f+ULdg(}

[root@isTester ~]# mysql

M%G_'r/^w,Y0

Welcome to the MySQL monitor.  Commands end with ; or \g.51Testing软件测试网m%tg~Q4v0^2\ l)t

Your MySQL connection id is 2

%y2w:lK!^c0

Server version: 5.7.30 MySQL Community Server (GPL)51Testing软件测试网K*h"_D%k#G


8F%[ X:_3\.G@D0

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


51Testing软件测试网&\f&A2_ p

Oracle is a registered trademark of Oracle Corporation and/or its51Testing软件测试网 l5@XBo7~'j

affiliates. Other names may be trademarks of their respective51Testing软件测试网;^,moKnTo:[a

owners.51Testing软件测试网1h8B? f U{'F\`uP


3A4T}$~?1a||0

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.51Testing软件测试网h'Tj vt


-vbxHOm0

mysql> 

1F.W"J Z0lE0


Il&I+X!B/vLa `0


'vV9Mz1G| CyUq0


5hK/sn-N0

5.修改root用户密码

\`$kI/Iz(H!j0

参考文章

$K X&hc Y%O J0


0zy^} Y)E6d.MG O Z0


51Testing软件测试网t(h.p7J#UV\ ByW

6./etc/my.cnf中的skip-grant-tables注释掉51Testing软件测试网2O|$J9J+FX/Az


51Testing软件测试网.j8x"d_CE|)_

参考第251Testing软件测试网3e S5T6jZvH3O3\

# ADD free password by idoxu (isTester.com)

fZ!b v {%HV.EN8H'mg0

# skip-grant-tables      # IDO老徐注:前面新增一个 # 注释掉这行51Testing软件测试网1|j9Vx/? Kir

~     

*f,c2},P,@,S\;C0


(P4@hU7Fy#b;M0


51Testing软件测试网#u*G,vA0[$R9U

7.重启mysql51Testing软件测试网 B3s"n E@ O;R h

参考第3

Y!RpAv0


"TO{Z+b-{ P0


k@B ~uJ7N J0mExT0

搞定,

[ ELy5z/s*y:Q4@/?0

可以用root新的密码登录了

6p"o&QsK-m [+v6[0

TAG:

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

xuquan

xuquan

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

日历

« 2021-01-21  
     12
3456789
10111213141516
17181920212223
24252627282930
31      

数据统计

  • 访问量: 648009
  • 日志数: 380
  • 建立时间: 2012-06-04
  • 更新时间: 2021-01-04

RSS订阅

Open Toolbar