易陆发现互联网技术论坛

 找回密码
 开始注册
查看: 1400|回复: 2
收起左侧

mariadb/mysql 数据库连接密码忘记了怎么办

[复制链接]
发表于 2022-1-5 13:53:19 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?开始注册

x
mariadb/mysql 数据库连接密码忘记了怎么办; K* ~0 U' S! {' {; G& J3 p0 @
vi /etc/my.cnf

/ F; M+ z+ g6 b* Q9 Q7 [5 F
将刚才在
) U$ o, u; ?- L
[mysqld]
9 f+ @+ i: k9 H: @/ d1 X, f

; U" u' I( c8 N3 ~% r* C" L
2 R- R, A7 P( r( P# n3 o
段中加上的

+ F8 a7 H0 P4 p9 d% b  b
skip-grant-tables

) `3 t# ?! ]! ^$ C8 y" v

6 ~% D2 R3 z6 p5 i: q: _

) k/ v# D7 b" Z) N# q3 f
删除

# K* S. n) B" m" O4 r$ B! H# N1 b
重启数据库服务:

- @4 a. d$ [; N0 k9 V" b2 E& E

% |) U. G2 n- Q+ }4 m( x( w4 ^7 W
# s) Y" z. r( z& V
+ }1 d  p( c& L' O

0 U  C& \  M! k4 u
通过其他方式修改:
直接修改密码。  R5 C" y8 |! z9 n
/ C' R6 t' H3 L5 C
本次操作所有需要用到的密令行:
/ y2 l; w( z- m$ s& m, D( W+ o0 P- m
; Q. p9 ~# W! w: O; Obin>net stop mysql, A% W( r# f2 `$ q( {4 M5 m" B
+ J# H/ _) @: z
bin>mysqld --skip-grant-tables
2 O: l& Q. Z% `8 z( w( ^( j! A& \* E
: ^1 f7 S! P& Q5 c' J3 L4 Nbin>mysql) h* g! a. |7 ]- A$ O$ t7 {& c7 q- P# r* m4 R
( j4 R  j% S2 _  J" i5 I3 K8 U
mysql>use mysql7 F. t  q2 X6 N

5 C4 x# d: z6 M) g: |6 i0 w. C: Gmysql>update user set password=password("123456") where user="root";$ S& P0 w! |' Z1 g" K

8 B, D# j1 j( K; i& G2 {mysql>flush privileges;' V- Y) ?. B% i! C& ]# o7 s

. N, `$ e# n6 W1 r# w* s- Lmysql>quit
- V. x! B% s3 @3 g- D  \
. q' D- D$ T2 h  T5 J, a% qbin>mysqladmin -u root -p shutdown/ f( |* F/ p/ _. q9 y4 C
+ f9 i. }2 P- k' m& Z9 \  i( Z
bin>net start mysql
5 Z! c0 p  p. Y3 [
, i: u1 B2 i& j4 @8 `8 ^9 ~9 V8 E* Z
 楼主| 发表于 2022-1-5 13:55:09 | 显示全部楼层
直接修改密码。4 Z7 D" ]& T; W4 b: X, o

# y' V$ k- \- c0 |  W* c) \- [3 e- S本次操作所有需要用到的密令行:. Q! E: j5 B( Q: r* E3 F$ h$ c

+ Y! m8 r4 Q6 a) X2 Ubin>net stop mysql
: n/ Q. V3 `5 y1 E. G# F9 a& `  P* t" c
bin>mysqld --skip-grant-tables0 P5 U+ l$ x5 o- j& D
" Q# }5 d* G4 J7 ~9 [  l$ _2 p$ Q
bin>mysql8 h8 O. r1 a, j; }. d$ U1 |
( B3 Q# W" N, d& ?$ p8 @
mysql>use mysql
( a! m' ~- Q7 x! w7 t1 y7 {1 f! T$ }! e0 |; ?# S4 M1 e
mysql>update user set password=password("123456") where user="root";
2 t6 ~: ~  v1 Z. G
4 ?0 _/ w% [+ b( h; g. Qmysql>flush privileges;
2 X7 ~' l9 ]: J1 y& g8 c, ]/ }. S4 j3 i% S8 x- N. O' Q4 R: Q7 d
mysql>quit
. q( Z% _5 X; q8 Q3 ~+ ~' A5 p. K/ K: u$ z4 p7 t$ {
bin>mysqladmin -u root -p shutdown
% t( d8 t, z4 b2 W/ u
0 J( i, O3 `3 P6 T8 E. Tbin>net start mysql4 L, P" F% |  E3 d
0 P2 V- r6 u  f0 W( d$ {1 U

: Q. ~$ b2 J9 Y* U
 楼主| 发表于 2024-7-9 22:21:14 | 显示全部楼层
windows版本忘记密码,修改my.ini文件,添加. _$ p( d, B3 ]
[mysqld]
- z+ o3 ~& F" z% A# t  \( }! p* @5 M
4 f- P% d6 C7 \9 I3 z8 V& C% D. S7 Z8 r/ |
2 ?' U6 |3 a5 Y) q3 e- I) Y
段中加上的
6 b+ j# z  ]) F
5 u! y& G* A$ r) ^1 k$ a* T8 c9 rskip-grant-tables
  l1 O, A) Q" o4 ^0 l: M
& ?4 v' [9 D' [2 b9 Q( {' v* j- a, Z9 U% R9 V9 H- {# r. n+ k8 i
找到服务,找到mysql数据库,右键重启即可。
* ~3 j  d5 p# s; i# |, b
  S4 U9 k/ V. k% t3 sC:\Users\admin>mysql -u root -p; [% S8 ^% s/ U) D3 T; e2 T% g
Enter password: ********8 |& ^/ z" l) C' t
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)4 h  p9 K. p8 \+ L/ f

7 ?4 R! G; T. V4 n6 c) qC:\Users\admin>mysql -u root -p/ ^7 }/ p! x4 P9 t8 ~
Enter password:% @0 \8 @4 s( F$ v% p& O" C
Welcome to the MariaDB monitor.  Commands end with ; or \g.
/ T( f$ [; Y; W3 l8 ?7 ]Your MariaDB connection id is 3" u) F; d" Z* Y- `
Server version: 11.5.1-MariaDB mariadb.org binary distribution! L* W. m& [, E2 y# H/ @- J3 d
2 A  F8 D# u& r/ {4 x( a, ?0 N( _
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.( e4 B& I( g. ~
& r# C7 S& s0 J1 p" p8 U( u2 M5 |
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.8 Z+ w% @, @" ~/ b; ]5 c
- A9 r& |; f4 t8 Z. l
MariaDB [(none)]>
: T' \. Z6 l& |. I8 @+ A9 ?MariaDB [(none)]>
, y8 h. a! u* E7 n3 w0 pMariaDB [(none)]>
, t: N7 y" E3 Y+ e. d; I/ f! S- K% E0 M3 X/ K$ ?- I
问题解决。
! w4 N6 w, D0 z5 d) G5 s; _
您需要登录后才可以回帖 登录 | 开始注册

本版积分规则

关闭

站长推荐上一条 /4 下一条

北京云银创陇科技有限公司以云计算运维,代码开发

QQ|返回首页|Archiver|小黑屋|易陆发现技术论坛 点击这里给我发消息

GMT+8, 2026-4-8 15:15 , Processed in 0.049690 second(s), 21 queries .

Powered by Discuz! X3.4 Licensed

© 2012-2025 Discuz! Team.

快速回复 返回顶部 返回列表