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

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

相关推荐

  • jq如何修改css属性

    技术jq如何修改css属性本篇内容介绍了“jq如何修改css属性”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

    攻略 2021年11月17日
  • DG主库忘记force logging情况下insert append了nologgin表操作是怎样的

    技术DG主库忘记force logging情况下insert append了nologgin表操作是怎样的这篇文章给大家介绍DG主库忘记force logging情况下insert append了nologgin表操作是

    攻略 2021年11月30日
  • Python如何将数字转化成列表

    技术Python如何将数字转化成列表小编给大家分享一下Python如何将数字转化成列表,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!1. digitizedef digitize(n):
    retur

    攻略 2021年11月11日
  • Redis要比Memcached更火的原因有哪些

    技术Redis要比Memcached更火的原因有哪些本篇内容介绍了“Redis要比Memcached更火的原因有哪些”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这

    攻略 2021年10月22日
  • go语言如何处理TCP拆包/粘包

    技术go语言如何处理TCP拆包/粘包这篇文章主要讲解了“go语言如何处理TCP拆包/粘包”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“go语言如何处理TCP拆包/粘包”吧

    攻略 2021年12月9日
  • 支付宝怎么交违章罚款,2021支付宝怎么交违章停车

    技术支付宝怎么交违章罚款,2021支付宝怎么交违章停车1、下载交管12123APP,用车主身份证注册,进去后可以看到车主身份证下所有车辆的情况支付宝怎么交违章罚款。按照说明一步步走下去就可以了。
    2、上支付宝,找到更多,

    生活 2021年10月22日