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

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

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

51Testing软件测试网eV4v7]N)o/{4~M

前提,51Testing软件测试网RCR f5~ R Uai

能登录到mysql的这台Linux服务器 ;51Testing软件测试网uQ(~3_4N`L


r(cD7yF2[-u s0


H%c D_6~&v |Vg0

已经忘记了mysql root密码,无法登录的情况下,51Testing软件测试网w|.nBT9A&{

限于有权限修改mysql安装文件(此方法适用于linux 
51Testing软件测试网 v,TKj@9rf


'TSz0Ps+T ~bH0


Linux为例: 

ys rS l;?Esp`}~h0


51Testing软件测试网#@ aft0q


b2gD/Km{0

1.编辑/etc/my.cnf配置文件,vim /etc/my.cnf51Testing软件测试网:U%Wh I(N*go y


51Testing软件测试网!v?*[v(L:`x)e(B7?


S?4R7lF1RiP0

2.在[mysqld]下添加一行 skip-grant-tables,然后保存并退出51Testing软件测试网,t&]}r/V0v5G


51Testing软件测试网a9my4t-Y5I0a

[mysqld]51Testing软件测试网 B(}.L#R6a$[

#51Testing软件测试网.`MliE?

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

6WBt)AC8QU6n0

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

5GU2VagsmR0

# innodb_buffer_pool_size = 128M

5z6\[@!r}.k3g)kVR0

#

lk }UUB-r,V0

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

8z)p%VnK'T4M0

# changes to the binary log between backups.

)H Kq3pl0

# log_bin51Testing软件测试网,Bv_)q#nF0[?2V(x K

#51Testing软件测试网D0Q A#|_%U y:z

# Remove leading # to set options mainly useful for reporting servers.

(U O7i$Tz5z^0

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

6yX{ _ZN,D0

# Adjust sizes as needed, experiment to find the optimal values.51Testing软件测试网$M'@o \~*Zv

# join_buffer_size = 128M51Testing软件测试网tW`\4_/B/DL

# sort_buffer_size = 2M

X h7~.L5Xu0

# read_rnd_buffer_size = 2M51Testing软件测试网v Rh _2B+hP'of wUe

datadir=/var/lib/mysql

8L!YpD&na6S Ej?0

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

-EWE"GC0


r(`vo#reu.^0

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

1]F,L] t.vZ0

symbolic-links=0

A[/M,H ?I g {9R;`0


51Testing软件测试网w)U'gsGp4[

log-error=/var/log/mysqld.log51Testing软件测试网X$P Gh2hRmpF

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

%xZ)Ud"?rEz7W0


8G%J:vai0


51Testing软件测试网5WdR%Qj+|Srd

# ADD free password by idoxu (isTester.com)

gM)b$A~u3ul^}0

skip-grant-tables      # IDO老徐注:新增这行51Testing软件测试网6d+Vcw"s

                                                                                                                                     

V;A-CRKw0

~                                                       51Testing软件测试网m3o|3x o"Y2d{%W


P[A-`.W0

3.重启mysql服务:service mysqld restart

+c4zL b+Mu[n-}0y0

51Testing软件测试网 Y nf*{-c

[root@isTester ~]# service mysqld restart51Testing软件测试网 q+X,Np)k4sP

Redirecting to /bin/systemctl restart mysqld.service51Testing软件测试网,l Y1b+KW*AD

[root@isTester ~]# 

Fw&||*I!MX0

!uGcsT(?)gN$R$H0

51Testing软件测试网e XUo h


51Testing软件测试网hm9d~*u^`(t


51Testing软件测试网5i`(hI.\@.T+~

4.更改root密码51Testing软件测试网t_*Cr$I{&j|,r-S

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

)x-yED;B!]gI;O{)\,n0


;yvsZn:un{r0

[root@isTester ~]# mysql

n^u&U'G Idi3[ \0

Welcome to the MySQL monitor.  Commands end with ; or \g.51Testing软件测试网O7C)p tO5V"q'D,A)j9S

Your MySQL connection id is 251Testing软件测试网(by!vF1D9EO

Server version: 5.7.30 MySQL Community Server (GPL)

HS:}'mX0


AX[ C,Ou-rgW0

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

dcBU$nQ7x0


51Testing软件测试网+_&hmle u\;G

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

TMQ8b b0fn*?*|j N0

affiliates. Other names may be trademarks of their respective

Hi~X|.YX0

owners.51Testing软件测试网*d9WsLqej Q4I


s4\6n"qnGKY Mr0

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

F,P5z*Lv]-{7qR/c0


51Testing软件测试网&P] k:d)]on)r

mysql> 51Testing软件测试网Ty:N2G8@VwD


51Testing软件测试网)^5oc,ST_'b aOj


_ W?x-d6VEIF p0


51Testing软件测试网F/V~5M B3t

5.修改root用户密码51Testing软件测试网g'^ _#q!fK!i

参考文章51Testing软件测试网0oBAWmvak


._%v'["{U9Qj0


51Testing软件测试网kDXe6q Q_

6./etc/my.cnf中的skip-grant-tables注释掉51Testing软件测试网!MG ihhG


c;ru!o#qw?4b0

参考第251Testing软件测试网w K1}+V5vP6Bs[

# ADD free password by idoxu (isTester.com)51Testing软件测试网/[!nG7tec)^&X9Z

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

.o]?C#Qc0

~     

u.c4Z P B8ts0


51Testing软件测试网&~ |n)@-l^:f.^


c;[N&H g7QI-p&t%Y!@0

7.重启mysql51Testing软件测试网(_Ti7Y+y%t'q

参考第351Testing软件测试网@.qY` F-t


51Testing软件测试网4i A$t)Ch


51Testing软件测试网 u0[ l]5xeR Y

搞定,51Testing软件测试网"OK){#U4y-DP.g'E!]

可以用root新的密码登录了51Testing软件测试网 HPK2I`zP J)[


TAG:

 

评分:0

我来说两句

xuquan

xuquan

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

日历

« 2024-04-11  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

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

RSS订阅

Open Toolbar