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

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

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


6Mc(^wva`0

前提,51Testing软件测试网 sg}O]"a$~

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

KK B#NTH9N|0


51Testing软件测试网/s:Oo"CI*z


3yF6G7X/qy|0

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

,n%K/F!?N9gd:S0Kr0iK0

限于有权限修改mysql安装文件(此方法适用于linux 
51Testing软件测试网5s\5Q(c,FN0Ko


51Testing软件测试网4RZQms


Linux为例: 

d `C.`'b D)Bv0


51Testing软件测试网 S|c1_|D8p


uT:Pf%^l}0oM5u$[0

1.编辑/etc/my.cnf配置文件,vim /etc/my.cnf51Testing软件测试网x\+V3m,x


ka3y~BmcI]uK0


;G]e$~G1HFs0

2.在[mysqld]下添加一行 skip-grant-tables,然后保存并退出51Testing软件测试网W Vi:?SN


51Testing软件测试网BIrKY@V&o

[mysqld]

nw)\9M6yRqv"~R/c0

#

.M/?p E)[M"Kj$W0

# Remove leading # and set to the amount of RAM for the most important data51Testing软件测试网0ev3uw5NH:\

# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.51Testing软件测试网.V*^ Gl:q5p/^rT

# innodb_buffer_pool_size = 128M51Testing软件测试网Wk @1{G3E&Z

#

a%QO``4N"?6O0

# Remove leading # to turn on a very important data integrity option: logging51Testing软件测试网h/d?+g(`-_,fC

# changes to the binary log between backups.51Testing软件测试网F S9fz~%f

# log_bin

L%wBK~1t"^.v0

#

q*\3`mpNE.a^B0

# Remove leading # to set options mainly useful for reporting servers.51Testing软件测试网0M2l bj\I2e$k,G(?

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

lI)\6So Y#ZiAZ0

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

/J^l0B~Y0

# join_buffer_size = 128M51Testing软件测试网\s._8W ^6H

# sort_buffer_size = 2M51Testing软件测试网f_S j j$P,J

# read_rnd_buffer_size = 2M51Testing软件测试网#\z.h(sT3FI}G

datadir=/var/lib/mysql

5z%n5N|*OVaM B0C0

socket=/var/lib/mysql/mysql.sock51Testing软件测试网/\e#b~i!Q


51Testing软件测试网)hF5uXsHfk~

# Disabling symbolic-links is recommended to prevent assorted security risks51Testing软件测试网@;\9Mt8J1k)S[IP$` ]

symbolic-links=0

d5I(h(l\;OW?:v0


51Testing软件测试网'j#M,i,XHumUg-k

log-error=/var/log/mysqld.log51Testing软件测试网i5g ~or!q

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

UIB@ [B0


51Testing软件测试网 X8l9^YK w


e3aDmdH{+u g0

# ADD free password by idoxu (isTester.com)51Testing软件测试网 d2P)]c:^ o(|*I

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

A!q Tly y(fGHz0

                                                                                                                                     

9z,K,t9Pds"W0z!o?0

~                                                       51Testing软件测试网Jc2L&\:T


"H2| lC4H&K7g0

3.重启mysql服务:service mysqld restart

V"DlLm$] [.}9pc0

51Testing软件测试网2bK8p M@W

[root@isTester ~]# service mysqld restart

i)t&}$X4VP0

Redirecting to /bin/systemctl restart mysqld.service51Testing软件测试网9K] rY:O;L

[root@isTester ~]# 51Testing软件测试网;G]HlQ6k8L

51Testing软件测试网 H@R2x!~Eb

51Testing软件测试网Kt^1[r7_3n"aX


51Testing软件测试网v+OQivNJ


?9^cIhtN0

4.更改root密码

0r;jf)X3@J.p&L5y0

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

$L6`jxpw,aM8y0


:|3kiY+`4F2b0

[root@isTester ~]# mysql51Testing软件测试网,wg qRM_ g

Welcome to the MySQL monitor.  Commands end with ; or \g.51Testing软件测试网%|P3PEr s^9y+?7Z

Your MySQL connection id is 2

jmNt6`+Z8Mo0

Server version: 5.7.30 MySQL Community Server (GPL)51Testing软件测试网w+F3_ YH?l


51Testing软件测试网:Gm/kN#mS,m

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

V7e4zj x0


51Testing软件测试网Ib[+Ryt

Oracle is a registered trademark of Oracle Corporation and/or its51Testing软件测试网"I0\4W;Jj/~xx{:A|%B

affiliates. Other names may be trademarks of their respective

2V/W&y:K#o O,ACC0

owners.51Testing软件测试网 J:Gw9kbTV f


51Testing软件测试网O,~7`1F-r^4y1V#vL7k

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

X'Q8hKZ d0


's7v:f|O3|]Tw2IRU0

mysql> 

I s7y*fg/fM0


51Testing软件测试网d#} rB;^a!gI"SQh


}XDs] f"Mh G!`K%@0


uyVn5UwP u.j0

5.修改root用户密码

O8dF%n ZX;Z h0

参考文章

n+` ?hx0


51Testing软件测试网&w(Xj @-]6h#p%x


u:p7B/\7s2X[Y!q0

6./etc/my.cnf中的skip-grant-tables注释掉51Testing软件测试网'j T#I P|


F[ |P|0

参考第251Testing软件测试网vtno_NT*N

# ADD free password by idoxu (isTester.com)51Testing软件测试网5`e-XuL7{P

# skip-grant-tables      # IDO老徐注:前面新增一个 # 注释掉这行

2o"t.S INr:v6i0

~     51Testing软件测试网`]k.nw&i*J


51Testing软件测试网&DF6x%buN


51Testing软件测试网 ^ M+y,Oquq5T0E

7.重启mysql

&}/H,\ x j'EkJ6N6A~0

参考第351Testing软件测试网V&ln{hQ/K8g#S


wEwt3gk'SH:u%g~0


^ C*O5p`|I A:R f8W0

搞定,51Testing软件测试网-^,S-wS }b w6G

可以用root新的密码登录了51Testing软件测试网6s;zvw2G)X1J/c


TAG:

 

评分:0

我来说两句

xuquan

xuquan

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

日历

« 2022-01-14  
      1
2345678
9101112131415
16171819202122
23242526272829
3031     

数据统计

  • 访问量: 758036
  • 日志数: 421
  • 建立时间: 2012-06-04
  • 更新时间: 2022-01-11

RSS订阅

Open Toolbar