当前位置: 首页 > news >正文

mysql进阶-用户密码的设置和管理

一、修改密码

1.1 修改自己的密码

方式一:
推荐使用

alter user user() identified by '新密码';

方式二:

set password ='新密码';

演示

[root@VM-4-6-centos /]# mysql -uzhang3 -p@ZhangSan123456
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 351
Server version: 5.7.43 MySQL Community Server (GPL)Copyright (c) 2000, 2023, 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 user() identified by '@ZhangSan123';
Query OK, 0 rows affected (0.00 sec)mysql> quit;
Bye
[root@VM-4-6-centos /]# mysql -uzhang3 -p@ZhangSan123456
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'zhang3'@'localhost' (using password: YES)
[root@VM-4-6-centos /]# mysql -uzhang3 -p@ZhangSan123
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 353
Server version: 5.7.43 MySQL Community Server (GPL)Copyright (c) 2000, 2023, 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> set password ='@ZhangSan123456';
Query OK, 0 rows affected (0.00 sec)mysql> quit;
Bye
[root@VM-4-6-centos /]# mysql -uzhang3 -p@ZhangSan123
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'zhang3'@'localhost' (using password: YES)
[root@VM-4-6-centos /]# mysql -uzhang3 -p@ZhangSan123456
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 355
Server version: 5.7.43 MySQL Community Server (GPL)Copyright (c) 2000, 2023, 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> 

2.2 修改其他用户的密码

需要root权限,一般只有root账号可以修改其他用户的密码

方式一:

alter user 'user_name'@'host_name' identified by 'new_password';

方式二:

set password for 'user_name'@'host_name'='new_password';

示例:

mysql> alter user 'zhang3'@'localhost' identified by '@ZhangSan123';
Query OK, 0 rows affected (0.00 sec)mysql> set password for 'zhang3'@'localhost'='@ZhangSan123456';
Query OK, 0 rows affected (0.00 sec)mysql> 

二、管理密码

2.1 系统默认设置

默认是所有账号永不过期

 set persist default_password_lifetime = 0;

2.2 设置所有账号指定时间后过期

 set persist default_password_lifetime = 365;//365天后所有密码过期 

2.3 设置指定账号永不过期

alter user 'zhang3'@'localhost' PASSWORD EXPIRE NEVER;

2.4 设置指定账号密码立即过期

设置完之后,立即过期,账号zhang3能登入但是无法操作数据,必须重新设置密码

ALTER USER ‘zhang3’@'localhost' PASSWORD EXPIRE;

2.5 设置指定账号密码固定周期时间过期

每隔90天过期

ALTER USER ‘zhang3’@'localhost' PASSWORD EXPIRE INTERVAL 90 DAY;
http://www.lryc.cn/news/106262.html

相关文章:

  • 2023年最新智能优化算法之——切诺贝利灾难优化器 (CDO),附MATLAB代码和文献
  • uniapp跨域解决
  • 力扣-94、144、145-前中后序遍历
  • 什么是线程?为什么需要线程?和进程的区别?
  • 【业务功能篇61】SpringBoot项目流水线 dependencyManagement 标签整改依赖包版本漏洞问题
  • uniapp使用getStorage对属性赋值无效
  • 20230802-下载并安装android-studio
  • python 第九章 —— GUI界面开发(tkinter详解)
  • 线段树合并例题
  • Stable Diffusion 硬核生存指南:WebUI 中的 VAE
  • vue项目 前端加前缀(包括页面及静态资源)
  • 使用文心一言等智能工具指数级提升嵌入式/物联网(M5Atom/ESP32)和机器人操作系统(ROS1/ROS2)学习研究和开发效率
  • 【Rust 基础篇】Rust动态大小类型:理解动态大小类型与编写安全的代码
  • 【Python】使用nuitka打包Python程序为EXE可执行程序
  • 背景图片及精灵图
  • 简要介绍 | 生成模型的演进:从自编码器(AE)到变分自编码器(VAE)和生成对抗网络(GAN),再到扩散模型
  • 8.2Thread类的常见属性
  • 博客摘录「 mvvm框架工作原理及优缺」2023年7月31日
  • 第12章 Linux 实操篇-Linux磁盘分区、挂载
  • 使用express搭建后端服务
  • 深度学习——划分自定义数据集
  • Jmeter性能测试之正则表达式提取器
  • 浅谈Kubernetes中Service网络实现(服务发现)
  • 【重造轮子】golang实现可重入锁
  • torch显存分析——对生成模型清除显存
  • electron+vue+ts窗口间通信
  • 基于Fringe-Projection环形投影技术的人脸三维形状提取算法matlab仿真
  • 如何使用Webman框架实现多语言支持和国际化功能?
  • 接受平庸,特别是程序员
  • HTML兼容性