加入收藏 | 设为首页 | 会员中心 | 我要投稿 焦作站长网 (https://www.0391zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > 产品 > 正文

MySQL修改密码的几种方式

发布时间:2020-12-18 16:48:45 所属栏目:产品 来源:互联网
导读:这篇文章主要介绍了MySQL修改密码的几种方式,帮助大家更好的理解和使用MySQL,感兴趣的朋友可以了解下

# 5.7及之后版本 
mysql> update mysql.user set authentication_string = password ('Password4') where user = 'testuser' and host = '%'; 
Query OK, 1 row affected, 1 warning (0.06 sec) 
Rows matched: 1  Changed: 1  Warnings: 1 
 
mysql> flush privileges; 
Query OK, 0 rows affected (0.01 sec) 
 
# 5.6及之前版本 
update mysql.user set password=password('新密码') where user='用户名' and host='host';  

3.设置 login-path 本地快捷登陆

为了防止密码暴露及忘记密码,我们还可以设置 login-path 来实现在本地不输密码快捷登录。

login-path 是 MySQL 5.6 开始支持的新特性。通过借助 mysql_config_editor 工具将登陆 MySQL 服务的认证信息加密保存在 .mylogin.cnf 文件(默认位于用户主目录)。MySQL 客户端工具可通过读取该加密文件连接 MySQL ,实现快捷登录。

假设我们想配置 root 账号在本地快捷登录,可以这么做:

# 执行回车后需要输入一次root密码 
[root@host ~]# mysql_config_editor set --login-path=root -uroot  -hlocalhost -p -P3306  
Enter password:  
 
# 配置完成后可以使用login-path登录 
[root@host ~]# mysql --login-path=root 
Welcome to the MySQL monitor.  Commands end with ; or g. 
Your MySQL connection id is 2919 
Server version: 5.7.23-log MySQL Community Server (GPL) 
 
Copyright (c) 2000, 2018, 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>  

总结:

本篇文章主要介绍了修改数据库账号密码的几种方法,基本涵盖了所有的场景。这里也提醒下各位,数据库账号最好限制ip段登录,密码尽量复杂些,最好能够定期修改,特别是重要的环境不能有半点马虎。年底了,安全才是王道。

(编辑:焦作站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读