数据库重设登录密码以及忘记密码该怎么办?(5.6版本和5.7版本)

   日期:2020-11-03     浏览:209    评论:0    
核心提示:一、重设密码方法一:mysql>use mysql mysql>update user set authentication_string=password('newpass') where user='root'; //5.7版本mysql> update mysql.user set password=PASSWO

一、重设密码

方法一

mysql>use mysql  

mysql>update user set authentication_string=password('newpass') where user='root'; //5.7版本
mysql> update mysql.user set password=PASSWORD(’新密码’) where User=’root’; //5.6版本
mysql>flush privileges;#刷新一下

方法二

#mysqladmin -u 用户 password ‘newpassword’
[root@server1 ~]# mysqladmin -u lisi -p password '123456';
Enter password: #这里输入原密码
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety

方法三

以root身份进入数据库
[root@server1 ~]# mysql -uroot -p123456
mysql> SET PASSWORD = PASSWORD('新密码'); //root用户
mysql> SET PASSWORD FOR 用户 = PASSWORD(‘新密码');//普通用户

二、忘记密码

修改mysql的配置文件:

vi /etc/my.cnf
[mysqld] 模块下
末尾添加
skip_grant_tables   就是在启动mysql时不启动grant-tables,授权表,跳过表的加载

重启数据库服务

systemctl restart mysqld

默认密码恢复为空,进入数据库,再修改密码字段

[root@server3 ~]# netstat -anpt | grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      1282/mysqld     
[root@server3 ~]# mysql -u root -p
Enter password:                            #回车直接登录
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.20 Source distribution
Copyright (c) 2000, 2017, 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> update user set authentication_string=password('xzf729') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

修改完密码后,再删除添加的配置文件那一行,重启服务,

vi /etc/my.cnf
[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock

[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1
[root@server1 ~]# systemctl restart mysqld
[root@server1 ~]# mysql -u root -p xzf729 #可登录成功
 
打赏
 本文转载自:网络 
所有权利归属于原作者,如文章来源标示错误或侵犯了您的权利请联系微信13520258486
更多>最近资讯中心
更多>最新资讯中心
0相关评论

推荐图文
推荐资讯中心
点击排行
最新信息
新手指南
采购商服务
供应商服务
交易安全
关注我们
手机网站:
新浪微博:
微信关注:

13520258486

周一至周五 9:00-18:00
(其他时间联系在线客服)

24小时在线客服