MariaDB Root密码恢复

本机装了MariaDB,很久不用,把密码给忘记了。

然后刚刚把密码恢复了下,记录一份这里方便以后索引。

  1. 停止MySQL服务。

# systemctl stop mysql 我是Ubuntu 这里服务名是这个

  1. 用无权限管理方式启动

# mysqld_safe --skip-grant-tables &

  1. 登录修改密码

# mysql -uroot

修改密码的SQL

1
2
3
4
> use mysql;
> update user set password=PASSWORD("gjdEdufD93J") where User='root';
> flush privileges;
> quit
  1. 停止mysql进程

/etc/init.d/mysql stop

  1. 启动服务 systemctl restart mysql

done.

全部流程记录

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
fate phan # systemctl stop mysql
fate phan # mysqld_safe --skip-grant-tables &
[1] 14391
fate phan # 170527 11:46:39 mysqld_safe Logging to syslog.
170527 11:46:39 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

fate phan # mysql -uroot
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 10.0.29-MariaDB-0ubuntu0.16.04.1 Ubuntu 16.04

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]> update user set password=PASSWORD("gjdEdufD93J") where User='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> quit
Bye
fate phan # /etc/init.d/mysql stop
[ ok ] Stopping mysql (via systemctl): mysql.service.
fate phan # systemctl restart mysql

参考资料

关注公众号 尹安灿