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

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

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

51Testing软件测试网%Mzr3z!UU q

前提,

Y$_4s*`$VK,iQd;r0

能登录到mysql的这台Linux服务器 ;51Testing软件测试网3j0j4p1u@u'N


51Testing软件测试网c9Y+x+^6NXu_


7q5rD P+Pi4s#F+tD0

已经忘记了mysql root密码,无法登录的情况下,51Testing软件测试网7s Y$a\6^~S T}.F

限于有权限修改mysql安装文件(此方法适用于linux 
51Testing软件测试网3qq|%Z nE1Lu+Vg


51Testing软件测试网"}d7D M4\/E%??#C1r


Linux为例: 51Testing软件测试网)N'e5E%V'tz'h.M$uU


51Testing软件测试网S[2m?#Pb3vl


\9o k!cfa]4Zq0

1.编辑/etc/my.cnf配置文件,vim /etc/my.cnf51Testing软件测试网9n:n$MB*f3B+A{Y


mI$o9~,wp]CNV0


51Testing软件测试网GB \%}!t;Lw

2.在[mysqld]下添加一行 skip-grant-tables,然后保存并退出51Testing软件测试网OOm@ WYW'djo


F Tb:WQ(R9gI o)Z0

[mysqld]51Testing软件测试网2_@ Z0YYx"Ae

#

4phU\R0

# Remove leading # and set to the amount of RAM for the most important data51Testing软件测试网Q3`%@y_J1d

# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.51Testing软件测试网;Xt:H$Z1U

# innodb_buffer_pool_size = 128M

]:yB3@7?BF.{0

#51Testing软件测试网)xk7R;gAn

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

0I2w3W)s%T5eM ~0_k0

# changes to the binary log between backups.51Testing软件测试网9VH3i'H i

# log_bin

-x@XsA!f1B0

#51Testing软件测试网2g8?fi"Y)I1k,L

# Remove leading # to set options mainly useful for reporting servers.51Testing软件测试网*t-S*O\SN*T g

# The server defaults are faster for transactions and fast SELECTs.51Testing软件测试网&V8cXDh2wZ"p

# Adjust sizes as needed, experiment to find the optimal values.51Testing软件测试网,KK&}1Z6l;s

# join_buffer_size = 128M51Testing软件测试网g"hT;N"re}Id

# sort_buffer_size = 2M

%J)M I\ DVf0

# read_rnd_buffer_size = 2M

hJW2\.NV\0

datadir=/var/lib/mysql

%f7i` vaNm8A0

socket=/var/lib/mysql/mysql.sock51Testing软件测试网5q(e4S s`_(XG


51Testing软件测试网4\m9otb]1K

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

"g,H&| \%k"}2h0

symbolic-links=051Testing软件测试网"B X wLa3X&o_-iWb


Z$P&ig"e+l0

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

]7Z Mw}'o0

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

^9K$kf JG0


51Testing软件测试网k J6JzKl#pk


51Testing软件测试网6yQ&Q R$W7n2B

# ADD free password by idoxu (isTester.com)

\x@$as"O/X0

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

B,Dr:i|T"]%P@2I0

                                                                                                                                     

ImK\.}b+K+_S'm0

~                                                       

yz:^"T6a$z0


Cb C"jfSp"N0

3.重启mysql服务:service mysqld restart

3UliXw!t0

UvZr,R0

[root@isTester ~]# service mysqld restart

]x4c1zQfq0

Redirecting to /bin/systemctl restart mysqld.service

M f$E5k D])U2Z0

[root@isTester ~]# 51Testing软件测试网V7r e z6A

51Testing软件测试网0qPQjp!f.Y(j

A b5d0Z5qh(B0


51Testing软件测试网2B4f ~B2u)u]R4a


Mz`V.f0

4.更改root密码51Testing软件测试网!`8n)G1iE2F*agP

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

Z:|Cy0V1^/c L8~ v!|0


51Testing软件测试网\RYVV;o V0x)d

[root@isTester ~]# mysql

*bv,}S"ML(["y"X0

Welcome to the MySQL monitor.  Commands end with ; or \g.

S;wh\ z:@$d7J0

Your MySQL connection id is 2

dh0W&Psz4WJ9J9M&d0

Server version: 5.7.30 MySQL Community Server (GPL)

[s\L3K0


&e8P"a6tNyvY0

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.51Testing软件测试网+yA;n ^ cH


3v3h}ZDZ,@0

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

D_T?h7]&e;{0

affiliates. Other names may be trademarks of their respective

#Ds(Pl@ q!w[1l0

owners.51Testing软件测试网VGxZS H"p d


3I/Q+D:uR KP0

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

g@J"v:~ \Ay.BZ T#L&I0


51Testing软件测试网@i$A2p X`!d h

mysql> 51Testing软件测试网x\xwk P w;y8H_


&Y v8b Z4[zL[0


51Testing软件测试网,H1qj`Q$B"jUrA


51Testing软件测试网Uq Um6zYwg&~ g

5.修改root用户密码

j,x)qq` h#e0

参考文章

1t&e ll^W0


,f(xOB4AE8b X0


51Testing软件测试网 A0L&b9h:~7d+pF6Y

6./etc/my.cnf中的skip-grant-tables注释掉51Testing软件测试网%[+nuY"}-Ua5}6q


Mk Yblq1]+g^ e0

参考第251Testing软件测试网`$~D/E2@

# ADD free password by idoxu (isTester.com)

:K5s2z P ]etXF0

# skip-grant-tables      # IDO老徐注:前面新增一个 # 注释掉这行51Testing软件测试网,cFX)je6M2q"s

~     

p{^ \R6N)[0


#F}W@Am^Xf&rP4D0


51Testing软件测试网0o O3g;ksW U r0`{

7.重启mysql51Testing软件测试网1pg2l9PL[

参考第3

'_x \d1qzr0


51Testing软件测试网l!A+j0{"n+u^`?


GO|"E D7[4|c0

搞定,51Testing软件测试网+mD iYdV#KU

可以用root新的密码登录了51Testing软件测试网 H$_8W pI J;sv


TAG:

 

评分:0

我来说两句

xuquan

xuquan

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

日历

« 2021-11-28  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 744457
  • 日志数: 412
  • 建立时间: 2012-06-04
  • 更新时间: 2021-10-15

RSS订阅

Open Toolbar