有哪些更改数据库密码的方式

技术有哪些更改数据库密码的方式这篇文章主要讲解了“有哪些更改数据库密码的方式”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“有哪些更改数据库密码的方式”吧!1.忘记 roo

本文主要讲解“更改数据库密码的方法有哪些”,文中的讲解内容简单明了,易学易懂。请跟随边肖的思路,一起学习学习“更改数据库密码的方法有哪些”。

1.忘记 root 密码

,忘记根密码的场景相当常见,尤其是自己搭建的测试环境长时间没有使用时,很容易忘记当时设置的密码。此时,常用的方法是跳过权限验证,然后更改根密码,然后启用权限验证。以MySQL版本为例,简单描述一下主要流程:
首先,修改配置文件并在[mysqld]部分添加一句话:skip-grant-tables。添加此参数的目的是跳过权限验证。然后重新启动数据库。数据库重新启动后,我们可以不用密码直接登录数据库,更改密码。
#在skip-grant-tables模式下修改root密码[root @ host ~]# mysqlwelcometothemysql monitor.command send with;或者\ g . yoursmysqlconnectionidis 16 server version :5 . 7 . 23-logmysql community server(GPL)版权所有(c)2000,2018,Oracleand/oritsaffiliates。所有权限都已恢复。oracleisaregisteredtrademarkoreclecorporation和/或oritsaffiliates。other name smaybetrademarksoftheirperspectivowners .键入“help”;或' \ h ' for help . type ' \ c ' to learrentputstatement . MySQL updatemysql . userset authentication _ string=password('xxxxx

x ')其中user=' root ' and host=' localhost ';QueryOK,0rowsaffected,1 warning(0.00秒)rowsmtched :1 changed :0 warning :1 myqlfhrusprivileges;修改根密码后,再次删除跳过授权表参数,然后重新启动数据库。

00-1010除了忘记密码,可能还有其他场景需要更改密码。此时,您可以用常见的方式更改密码。以MySQL版本为例,介绍了几种常用的更改密码的方法。

使用 alter user 修改

例如,如果您想更改testuser帐户的密码,我们可以使用root帐户登录,然后执行alter user命令来更改testuser帐户的密码。

MySQL alter user“test user ”@“%”由“Password1”标识;QueryOK,0rowsnb

sp;affected (0.01 sec)  mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)

使用 SET PASSWORD 命令

使用 SET PASSWORD 修改密码命令格式为 SET PASSWORD FOR 'username'@'host' =  PASSWORD('newpass'); 同样是使用 root 账号可修改其他账号的密码。

mysql> SET PASSWORD FOR 'testuser'@'%' = PASSWORD('Password2'); Query OK, 0 rows affected, 1 warning (0.00 sec)  mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)

使用 mysqladmin 修改密码

使用 mysqladmin 命令修改账号密码格式为 mysqladmin -u用户名 -p旧密码 password 新密码

[root@host ~]# mysqladmin -utestuser -pPassword2 password Password3 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@host ~]# mysql -utestuser -pPassword3 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 2388 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>

直接 update user 表

其实 MySQL 所以的账号信息都存储在 mysql.user 表里面,我们也可以直接通过 update user 表来修改密码。

# 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>

感谢各位的阅读,以上就是“有哪些更改数据库密码的方式”的内容了,经过本文的学习后,相信大家对有哪些更改数据库密码的方式这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是,小编将为大家推送更多相关知识点的文章,欢迎关注!

内容来源网络,如有侵权,联系删除,本文地址:https://www.230890.com/zhan/41741.html

(0)

相关推荐

  • 别人夸你优秀神回复,朋友夸我有才我怎么回复

    技术别人夸你优秀神回复,朋友夸我有才我怎么回复被别人夸奖别人夸你优秀神回复,怎样回答才显示出我们的高情商呢,我总结了下面五种回应方式仅供参考。
    1、以接受来回应
    如果别人夸你,而你又不知道怎么去回应的话,起码要接受并感谢

    生活 2021年10月21日
  • CentOS 6.5中如何搭建MySQL集群7.4

    技术CentOS 6.5中如何搭建MySQL集群7.4小编给大家分享一下CentOS 6.5中如何搭建MySQL集群7.4,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!各节点信息如下:管理节点:192.

    攻略 2021年11月15日
  • nodejs用哪些调试工具

    技术nodejs用哪些调试工具这篇文章将为大家详细讲解有关nodejs用哪些调试工具,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。 调试node的工具:1、

    攻略 2021年11月7日
  • 任劳任怨的意思,任劳任怨是不是描写人物精神的词

    技术任劳任怨的意思,任劳任怨是不是描写人物精神的词这个词在我们生活中可以说是用的很频繁了,基本上都用来评价别人的任劳任怨的意思。任劳任怨,读音rèn láo rèn yuàn,是一个成语;出自:清·颜光敏《颜氏家藏尺牍》

    生活 2021年10月23日
  • 大数据治理中如何搭建大数据探索平台

    技术大数据治理中如何搭建大数据探索平台这篇文章给大家介绍大数据治理中如何搭建大数据探索平台,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。在数据治理中,数据探索服务的价值在初期往往是被忽视的,但是随着

    攻略 2021年12月10日
  • docker容器网络配置

    技术docker容器网络配置 docker容器网络配置docker容器网络配置
    ip netns(网络名称空间)命令
    [root@Aimmi ~]# rpm -qa|grep iproute
    iprou

    礼包 2021年12月6日