织梦数据库账号密码忘记了-MySQL的root密码忘记怎么办 修改root密码的方式

如果有一天你忘记了在线 MySQL 数据库的 root 密码,你该怎么办?

大家经常会想到skip-grant-tables参数。 具体步骤如下:

1.关闭MySQL数据库。 由于root密码忘记,mysqladmin无法使用。 这时只能通过kill pid来关闭程序。

这里,我们来了解一下kill和kill -9的区别

默认参数下,kill向进程发送SIGTERM信号,告诉进程需要关闭,请停止运行并自行退出。

kill -9 向进程发送SIGKILL信号,告诉进程你已经被终止,请立即退出。与SIGTERM相比,这个信号无法被捕获或忽略,并且接收到此信号的进程在接收到此信号时无法进行任何清理。

因此,作为最后的手段,不要通过kill -9杀死进程。 这可能会导致MySQL数据库的物理结构损坏,无法重启。

2.在my.cnf文件的[mysqld]部分添加skip-grant-tables参数

3、登录数据库并修改root账户的密码

以下是修改root密码的三种方法:

1> mysql> 设置 root@localhost=password(123) 的密码; 无需刷新权限表

2> mysql> 更新 mysql.user 设置密码=密码(456),其中用户=root,主机=localhost;

mysql> 刷新权限;

3> # mysqladmin -u root 密码 123

4. 关闭数据库,注释掉skip-grant-tables参数,然后重新启动数据库。

虽然上面的方法很好,但是有一个问题。 您必须重新启动数据库,在线环境中可能不允许这样做。

再说说另一种方法,有点“黑科技”的味道。

该方法利用了mysql.user表或者MyISAM引擎的特性。

1、将该实例的mysql.user表复制到另一个实例的目录下,例如test数据库的目录

2、登录另一个实例数据库,修改上述三个文件的权限,并修改root密码

mysql> select user,host,password from test.user;+------+-----------+-------------------------------------------+| user | host | password     |+------+-----------+-------------------------------------------+| root | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |+------+-----------+-------------------------------------------+1 row in set (0.00 sec)mysql> update test.user set password=password(hello) where user=root and host=localhost;Query OK, 1 row affected (0.15 sec)Rows matched: 1 Changed: 1 Warnings: 0

3.将以上三个文件复制回源数据库

4、获取mysqld的pid织梦数据库账号密码忘记了,通过kill -HUP `pidof mysqld`让mysqld进程重新加载配置文件。

[root@keepalived01 ~]# mysql -phelloWarning: Using a password on the command line interface can be insecure.ERROR 1045 (28000): Access denied for user root@localhost (using password: YES)[root@keepalived01 ~]# kill -HUP 4283[root@keepalived01 ~]# mysql -phelloWarning: Using a password on the command line interface can be insecure.Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2528Server version: 5.6.26 MySQL Community Server (GPL)Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type help; or \h for help. Type \c to clear the current input statement.mysql> 

从上面的输出可以看出,在kill -HUP之前,直接使用密码hello登录是被拒绝的。 kill -HUP后就可以直接登录了。

当然,以上方法仅供参考,生产中应谨慎使用。 毕竟织梦数据库账号密码忘记了,安全是最重要的,天知道哪里会出现问题。

以上就是本文的全部内容。 希望可以帮助大家解决忘记root密码的问题。 感谢您的阅读。