【MySQL】密码管理

本文介绍了在CentOS7上MySQL5.7的密码管理,包括如何获取初始密码,遵循的密码规则,以及如何修改密码。在获取临时密码后,需要根据密码策略修改密码,然后可以使用新密码登录或通过远程工具如Navicat连接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

【测试环境】

  • CentOS7-64-1810
  • MySQL5.7

【获取初始密码】

数据库安装初始进入,需要获取临时密码,进入数据库后需要修改密码哟!

grep 'temporary password' /var/log/mysqld.log

使用临时密码登录

mysql -uroot -p0O4bBGgtiM*b

【修改密码】

修改密码前,我们需要先看一下密码规则情况(如果是复杂密码,则不需要看哈【默认一般是长度至少8位,大小写字母+数字+特殊符号】)

……好吧,初始时查看强制要求设置密码……

那还是先修改规则,改了密码之后再查看:

# 设置密码复杂度(0=最低)
set global validate_password_policy=0;

# 设置密码长度(0=不限)
set global validate_password_length=0;

现在就可以设置密码了:

ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
# 或者 SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');  


# 设置远程可访问
# (注意:mysql8.0 不支持此语句)
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; 

# mysql8.0 (使用此方式修改远程)
# use mysql;
# update user set host = '%' where user = 'root';

# 刷新 即时生效
flush privileges;

现在退出,使用新密码重新登陆即可(也可以远程使用工具如Navicat登录哟)

mysql> exit
Bye
[root@localhost ~]# mysql -uroot -p123456
mysql: [Warning] 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 3
Server version: 5.7.27 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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 VARIABLES LIKE 'validate_password%';  

当然还有其它的修改密码的方法,本文仅供参考哈。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值