mysql设置密码,修改密码,破解密码

目录

mysql官方文档

1. mysql中文文档地址:

2. mysql英文文档地址:

一、数据库设置密码:

1.命令行模式:

2.进入数据库设置密码:

二、数据库修改密码(需要知道旧密码):

1.命令行模式:

2.进入数据库修改密码:

三、破解密码(不记得密码)

第1步:让数据库服务不验证数据库运行

第2步:修改mysqld配置文件,使用“mysql”命令无密进入mysql

第3步:重置密码


mysql官方文档

1. mysql中文文档地址:

MySQL 中文文档 | MySQL 中文网

2. mysql英文文档地址:

MySQL :: MySQL Documentation

一、数据库设置密码:

1.命令行模式:

1.1 命令行终端输入:

mysqladmin -uroot -p password 密码

回车,提示输入密码,但是mysql初始化时没有密码,所以直接又是回车

1.2 验证mysql密码是否设置成功:

mysql -uroot -p

回车,输入密码,进入mysql页面

2.进入数据库设置密码:

2.1 在mysql命令行输入以下sql命令(alter开头的命令):

mysql> alter user root@主机 identified by 密码;

2.2 exit退出mysql后,再使用mysql -hlocalhost -uroot -p密码,回车进入数据库

安装mysql-server后:
[root@localhost ~]# systemctl enable mysqld --now
[root@localhost ~]# mysql
回车后进入mysql命令行:


Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.26 Source distribution

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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> alter user root@"localhost" identified by "123456";
Query OK, 0 rows affected (0.00 sec)

mysql> exit

推出mysql后使用:
mysql -hlocalhost -uroot -p123456
重新进入mysql,成功进入mysql就说明设置密码成功

二、数据库修改密码(需要知道旧密码):

1.命令行模式:

mysqladmin  -uroot -p password 新密码

回车,输入旧密码

验证mysql密码是否修改成功:

mysql -uroot -p

回车,输入新密码

2.进入数据库修改密码:

mysql> alter user root@"localhost" identified by "1234";

三、破解密码(不记得密码)

第1步:让数据库服务不验证数据库运行

1)vim /etc/my.cnf.d/mysql-server.cnf
加一行:
skip-grant-tables
其他不变

2)systemctl restart mysqld

第2步:修改mysqld配置文件,使用“mysql”命令无密进入mysql

此时不会验证密码,方便无密码进入mysql,清空authentication_string


[root@localhost ~]# mysqladmin  -uroot -p password "1234"
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@localhost ~]# mysql -uroot -p
Enter password:

#清空authentication_string
mysql> update mysql.user set authentication_string='' where host='localhost' and user='root';

#查看root的authentication_string的值是否清空了
mysql> select user,authentication_string from  mysql.user;

#重新加载授权表,使新的授权规则立即生效
mysql> flush privileges;


exit推出,将mysqld的配置改回去并重启mysqld:

1)vim /etc/my.cnf.d/mysql-server.cnf
注释掉 skip-grant-tables
其他不变

2)systemctl restart mysqld

第3步:重置密码

再使用“mysql”命令就可以直接进入数据库;

exit退出数据库,再走一遍设置密码的流程就行了(请查看“一、数据库设置密码”)。

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值