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

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

相关推荐

  • 怎么开源你的Python库

    技术怎么开源你的Python库这篇文章主要介绍了怎么开源你的Python库,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。1、源码将代码放在 GitHub

    攻略 2021年10月26日
  • 肉末茄子怎么做好吃又简单,饭店肉末茄子是怎么做的

    技术肉末茄子怎么做好吃又简单,饭店肉末茄子是怎么做的材料茄子(紫皮肉末茄子怎么做好吃又简单,长的那种)2-3个,猪肉 1小块,食盐适量,贵太太茶油50g,蒜适量,白糖适量,鸡精少许,料酒适量,豆瓣酱1大匙,小葱适量,生抽

    生活 2021年10月21日
  • html css js是什么

    技术html css js是什么本篇内容主要讲解“html css js是什么”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“html css js是什么”吧!最准确的网页设计

    攻略 2021年12月10日
  • jquery中=是什么意思

    技术jquery中=是什么意思这篇文章主要介绍“jquery中=是什么意思”,在日常操作中,相信很多人在jquery中=是什么意思问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”jquery

    攻略 2021年11月17日
  • 邯郸学步的故事,邯郸学步故事150个字概括

    技术邯郸学步的故事,邯郸学步故事150个字概括邯郸学步常用来比喻一味地模仿别人,不仅没有学到本事,反而把原来的本事也弄丢了邯郸学步的故事。这个成语告诉我们,每个人都有自己的特点,如果不考虑到实际情况一味地去模仿别人,结果

    生活 2021年10月30日
  • 怎么在Ubuntu 18.04服务器上安装TensorFlow

    技术怎么在Ubuntu 18.04服务器上安装TensorFlow小编给大家分享一下怎么在Ubuntu 18.04服务器上安装TensorFlow,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读

    攻略 2021年11月18日