mysql忘记root登录密码

没有过忘记密码的程序员是不完美的,对于Oracle忘记密码可以设置orapwdfile文件,

Mysql其中一种方法是通过修改文件免密然后再进行密码的修改:

1.忘记密码

[root@leader ~]# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@leader ~]#

2.修改文件/etc/my.cnf

修改文件前先停掉mysqld服务

[root@leader ~]# service mysqld stop
Stopping mysqld: [ OK ]
[root@leader ~]#vi /etc/my.cnf

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
skip-grant-table   ##添加该参数跳过密码验证

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

3,重启服务进行密码修改

[root@leader ~]# service mysqld start
Starting mysqld: [ OK ]
[root@leader ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73 Source distribution

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

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.00 sec)

mysql> 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
mysql> update user set password=password('mysql123')where user='root' and host='localhost';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0

mysql>

 

posted on 2019-08-17 14:30  Leader.Z  阅读(165)  评论(0编辑  收藏  举报