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

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

相关推荐

  • 美国独享服务器租用特点

    技术美国独享服务器租用特点与廉价的虚拟主机不同,美国独享服务器需要单个网站或网络所有者使用服务器资源。服务器资源(如硬件、软件和操作系统)受到用户的完全控制。此外,物理服务器通常安装在数据中心内。虽然很多用户为了节省成本

    礼包 2021年11月3日
  • Elasticsearch有哪些面试题

    技术Elasticsearch有哪些面试题这篇文章主要为大家展示了“Elasticsearch有哪些面试题”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“Elasticsear

    攻略 2021年11月17日
  • 大量数据采集是不是必须使用代理ip

    技术大量数据采集是不是必须使用代理ip本篇文章给大家分享的是有关大量数据采集是不是必须使用代理ip,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。近几年互联网

    攻略 2021年10月28日
  • postman中form-data在java中怎么实现(postman怎么传string数组)

    技术postman怎么实现传递ArrayList 给后台小编给大家分享一下postman怎么实现传递ArrayList 给后台,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!postman 传递 Arra

    攻略 2021年12月18日
  • 207所,中国兵器工业集团207所怎么样

    技术207所,中国兵器工业集团207所怎么样答207所:中国兵器工业集团公司自2004年以来连年获A级中央企业,位居央企前列。发展现状
    兵器工业是国家安全的战略基础。
    人民兵工是我党领导和创建的第一个工业部门,历经无数战

    生活 2021年10月25日
  • Maven:解决IDEA无法下载源码

    技术Maven:解决IDEA无法下载源码 Maven:解决IDEA无法下载源码通过点击进IDEA反编译的代码文件处下载源代码Sources。IDEA提示报错,无法下载源代码。解决办法:
    mvn depe

    礼包 2021年11月22日