mysql5.7密码凭证,mysql 5.7 默认密码及密码修改

1. Mysql 5.7 在自动初始化数据库的时候,会生成root用户的默认密码。mysql

经过 grep "temporary password" /var/log/mysqld.log 命令,返回结果最后冒号后面的字符串就是root的默认密码。sql

05d8426b809a3d61004035a00e3bff53.png

使用此密码登陆后,Mysql 会要求第一件作的事就是改root密码,并且是要求强密码。能够经过set password=password('密码')来更改。数据库

2. 没法找到密码,忘记设置的是啥了centos

在/etc/my.cnf 中添加 skip-grant-tables 参数。此参数的做用是登陆Mysql 数据库不进行用户密码验证。ide

93de75e3301c69e3f017f7c77424e74b.png

修改后, 重启服务 systemctl restart mysqld.

[root@VM_0_15_centos ~]#service mysqld restart

Stopping mysqld: [ OK ]

Starting mysqld: [ OK ]

[root@VM_0_15_centos~]#mysql

Welcome to the MySQL monitor. Commands end with ; or\g.

Your MySQL connection idis 3Server version:5.7.26MySQL Community Server (GPL)

Copyright (c)2000, 2019, Oracle and/orits affiliates. All rights reserved.

Oracleis a registered trademark of Oracle Corporation and/orits

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 mysql.user set authentication_string=password('123456pswd') where user='root' and Host = 'localhost';

Query OK,1 row affected, 1 warning (0.00sec)

Rows matched:1 Changed: 1 Warnings: 1mysql>flush privileges;

Query OK, 0 rows affected (0.00sec)

mysql>quit

Bye

# 将/etc/my.cnf 中 skip-grant-tables 注释,重启服务

[root@VM_0_15_centos ~]#mysql -p

Enter password:

Welcome to the MySQL monitor. Commands end with ;or\g.

Your MySQL connection idis 3Server version:5.7.26Copyright (c)2000, 2019, Oracle and/orits affiliates. All rights reserved.

Oracleis a registered trademark of Oracle Corporation and/orits

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>

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.测试

设置一个简单的测试密码的话,如123456,会提示这个错误.ui

mysql>   alter user 'root'@'localhost' identified by 'password';this

或者  mysql>   set password=password("password");spa

mysql>show databases;

ERROR1820(HY000): You must reset your password using ALTER USER statement before executing this statement.

mysql> alter user 'root'@'localhost' identified by '123456pswd';

Query OK, 0 rows affected (0.00sec)

mysql>flush privileges;

Query OK, 0 rows affected (0.00sec)

mysql>show databases;+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| ops |

| performance_schema |

| sys |

+--------------------+

5 rows in set (0.00sec)

mysql>quit

Bye

bf565274a2bbc55c9c56aa6349a5ea7c.png

6c8c49b7fdf2d7cb6e5334ca18d53412.png

4a75b3bf84347f70be1027b7ce0f1cd4.png

3e24ca1e697ff431c0335fa7e66476d1.png

72988e87fb4a942795a742e92c45ca86.png

627a011bf307835bc12ecf020d241e0d.png

be0f3e7e220273bb2246f628bcb21499.png

f0f06f2f01c94047b720c31add38d9b5.png

5e42d8d7f3cd0386461b514d28af5d0e.png

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值