当前位置:网站首页 > R语言数据分析 > 正文

群晖修改root密码(群晖root密码忘记)



前言:

在日常使用数据库的过程中,难免会遇到需要修改账号密码的情景,比如密码太简单需要修改、密码过期需要修改、忘记密码需要修改等。本篇文章将会介绍需要修改密码的场景及修改密码的几种方式。

忘记 root 密码的场景还是比较常见的,特别是自己搭的测试环境经过好久没用过时,很容易记不得当时设置的密码。这个时候一般常用的方法是跳过权限验证,然后更改 root 密码,之后再启用权限验证。以 MySQL 5.7 版本为例简单讲下主要过程:

首先修改配置文件,在[mysqld]部分加上一句:skip-grant-tables ,加上此参数的目的是跳过权限验证。然后重启数据库,数据库再次启动后,我们就可以不用密码直接登录数据库修改密码了。

# skip-grant-tables 模式下修改root密码 

[root@host ~]# mysql 

Welcome tothe MySQL monitor.  Commands endwith; org. 

Your MySQL connectionid is16 

Server version: 5.7.23-log MySQL Community Server (GPL) 

Copyright (c) 2000, 2018, Oracle and/orits affiliates. Allrights reserved. 

Oracle isa registered trademark ofOracle Corporation and/orits 

affiliates. Other names may be trademarks oftheir respective 

owners. 

Type 'help;'or'h'forhelp. Type 'c'toclear the currentinput statement. 

mysql> updatemysql.usersetauthentication_string = password('xxxxxx') whereuser= 'root'andhost = 'localhost'; 

Query OK, 0 rowsaffected, 1 warning (0.00 sec) 

Rowsmatched: 1  Changed: 0  Warnings: 1 

mysql> flush privileges; 

Query OK, 0 rowsaffected (0.01 sec) 

修改完 root 密码后,再次去除 skip-grant-tables 参数,然后重启下数据库即可。

除去忘记密码,可能还有其他情景需要修改密码,这时候就可以采取普通方式修改密码了。还是以 MySQL 5.7 版本为例,介绍几种常用的修改密码的方法。

使用 alter user 修改

比如如果想更改 testuser 账号的密码,我们可以使用 root 账号登录,然后执行 alter user 命令更改 testuser 账号的密码。

mysql> alteruser'testuser'@'%'identified by'Password1'; 

Query OK, 0 rowsaffected (0.01 sec) 

mysql> flush privileges; 

Query OK, 0 rowsaffected (0.00 sec) 

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

mysql> SETPASSWORDFOR'testuser'@'%'= PASSWORD('Password2'); 

Query OK, 0 rowsaffected, 1 warning (0.00 sec) 

mysql> flush privileges; 

Query OK, 0 rowsaffected (0.00 sec) 

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

[root@host ~]# mysqladmin -utestuser -pPassword2 passwordPassword3 

mysqladmin: [Warning] Using a passwordonthe command line interface can be insecure. 

Warning: Since passwordwill be sent toserver inplain text, use ssl connectiontoensure passwordsafety. 

[root@host ~]# mysql -utestuser -pPassword3 

mysql: [Warning] Using a passwordonthe command line interface can be insecure. 

Welcome tothe MySQL monitor.  Commands endwith; org. 

Your MySQL connectionid is2388 

Server version: 5.7.23-log MySQL Community Server (GPL) 

Copyright (c) 2000, 2018, Oracle and/orits affiliates. Allrights reserved. 

Oracle isa registered trademark ofOracle Corporation and/orits 

affiliates. Other names may be trademarks oftheir respective 

owners. 

Type 'help;'or'h'forhelp. Type 'c'toclear the currentinput statement. 

mysql>  

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

# 5.7及之后版本 

mysql> updatemysql.usersetauthentication_string = password('Password4') whereuser= 'testuser'andhost = '%'; 

Query OK, 1 row affected, 1 warning (0.06 sec) 

Rowsmatched: 1  Changed: 1  Warnings: 1 

mysql> flush privileges; 

Query OK, 0 rowsaffected (0.01 sec) 

# 5.6及之前版本 

updatemysql.usersetpassword=password('新密码') whereuser='用户名'andhost='host';  

为了防止密码暴露及忘记密码,我们还可以设置 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 tothe MySQL monitor.  Commands endwith; org. 

Your MySQL connectionid is2919 

Server version: 5.7.23-log MySQL Community Server (GPL) 

Copyright (c) 2000, 2018, Oracle and/orits affiliates. Allrights reserved. 

Oracle isa registered trademark ofOracle Corporation and/orits 

affiliates. Other names may be trademarks oftheir respective 

owners. 

Type 'help;'or'h'forhelp. Type 'c'toclear the currentinput statement. 

mysql>  

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

以上就是MySQL修改密码的几种方式的详细内容,有什问题欢迎评论区留言。

学习C/C++编程知识,提升C/C++编程能力,欢迎关注UP一起来成长!

另外,UP在主页上传了一些学习C/C++编程的视频教程,有兴趣或者正在学习的小伙伴一定要去看一看哦!会对你有帮助的~

最后,如果你也想成为程序员,想要快速掌握编程,赶紧关注【】加入学习企鹅圈子吧!

里面有资深专业软件开发工程师,在线解答你的所有疑惑~编程语言入门“so easy”

编程学习书籍:

编程学习视频:

到此这篇群晖修改root密码(群晖root密码忘记)的文章就介绍到这了,更多相关内容请继续浏览下面的相关推荐文章,希望大家都能在编程的领域有一番成就!

版权声明


相关文章:

  • redhat-release(redhat-release安装)2025-04-17 22:54:05
  • prp两次离心法(landesberg二次离心法)2025-04-17 22:54:05
  • 微信linux arm(微信linux uos)2025-04-17 22:54:05
  • resnet(resnet18网络结构)2025-04-17 22:54:05
  • termux启动linux(termux启动kali命令)2025-04-17 22:54:05
  • vmware密钥11(vmware密钥10)2025-04-17 22:54:05
  • linux修改文件权限755(linux修改文件权限为root)2025-04-17 22:54:05
  • swagger如何访问(swagger文档访问地址)2025-04-17 22:54:05
  • spring教程百度网盘(spring揭秘pdf百度网盘)2025-04-17 22:54:05
  • cruise软件在汽车行业用的多吗(cruise软件在汽车行业用的多吗知乎)2025-04-17 22:54:05
  • 全屏图片