成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

又忘記密碼啦?教你幾種更改密碼的方式

數據庫
在日常使用數據庫的過程中,難免會遇到需要修改賬號密碼的情景,比如密碼太簡單需要修改、密碼過期需要修改、忘記密碼需要修改等。本篇文章將會介紹需要修改密碼的場景及修改密碼的幾種方式。

 前言:

在日常使用數據庫的過程中,難免會遇到需要修改賬號密碼的情景,比如密碼太簡單需要修改、密碼過期需要修改、忘記密碼需要修改等。本篇文章將會介紹需要修改密碼的場景及修改密碼的幾種方式。

[[358336]]

1.忘記 root 密碼

忘記 root 密碼的場景還是比較常見的,特別是自己搭的測試環境經過好久沒用過時,很容易記不得當時設置的密碼。這個時候一般常用的方法是跳過權限驗證,然后更改 root 密碼,之后再啟用權限驗證。以 MySQL 5.7 版本為例簡單講下主要過程:

首先修改配置文件,在[mysqld]部分加上一句:skip-grant-tables ,加上此參數的目的是跳過權限驗證。然后重啟數據庫,數據庫再次啟動后,我們就可以不用密碼直接登錄數據庫修改密碼了。

 

  1. # skip-grant-tables 模式下修改root密碼 
  2. [root@host ~]# mysql 
  3. Welcome to the MySQL monitor.  Commands end with ; or \g. 
  4. Your MySQL connection id is 16 
  5. Server version: 5.7.23-log MySQL Community Server (GPL) 
  6.  
  7. Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. 
  8.  
  9. Oracle is a registered trademark of Oracle Corporation and/or its 
  10. affiliates. Other names may be trademarks of their respective 
  11. owners. 
  12.  
  13. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 
  14.  
  15. mysql> update mysql.user set authentication_string = password ('xxxxxx'where user = 'root' and host = 'localhost'
  16. Query OK, 0 rows affected, 1 warning (0.00 sec) 
  17. Rows matched: 1  Changed: 0  Warnings: 1 
  18.  
  19. mysql> flush privileges
  20. Query OK, 0 rows affected (0.01 sec) 

修改完 root 密碼后,再次去除 skip-grant-tables 參數,然后重啟下數據庫即可。

2.幾種修改密碼的方法

除去忘記密碼,可能還有其他情景需要修改密碼,這時候就可以采取普通方式修改密碼了。還是以 MySQL 5.7 版本為例,介紹幾種常用的修改密碼的方法。

使用 alter user 修改

比如如果想更改 testuser 賬號的密碼,我們可以使用 root 賬號登錄,然后執行 alter user 命令更改 testuser 賬號的密碼。

 

  1. mysql> alter user 'testuser'@'%' identified by 'Password1'
  2. Query OK, 0 rows affected (0.01 sec) 
  3.  
  4. mysql> flush privileges
  5. Query OK, 0 rows affected (0.00 sec) 

使用 SET PASSWORD 命令

使用 SET PASSWORD 修改密碼命令格式為 SET PASSWORD FOR 'username'@'host' = PASSWORD('newpass'); 同樣是使用 root 賬號可修改其他賬號的密碼。

 

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

使用 mysqladmin 修改密碼

使用 mysqladmin 命令修改賬號密碼格式為 mysqladmin -u用戶名 -p舊密碼 password 新密碼

 

  1. [root@host ~]# mysqladmin -utestuser -pPassword2 password Password3 
  2. mysqladmin: [Warning] Using a password on the command line interface can be insecure. 
  3. Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety. 
  4. [root@host ~]# mysql -utestuser -pPassword3 
  5. mysql: [Warning] Using a password on the command line interface can be insecure. 
  6. Welcome to the MySQL monitor.  Commands end with ; or \g. 
  7. Your MySQL connection id is 2388 
  8. Server version: 5.7.23-log MySQL Community Server (GPL) 
  9.  
  10. Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. 
  11.  
  12. Oracle is a registered trademark of Oracle Corporation and/or its 
  13. affiliates. Other names may be trademarks of their respective 
  14. owners. 
  15.  
  16. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 
  17.  
  18. mysql>  

直接 update user 表

其實 MySQL 所以的賬號信息都存儲在 mysql.user 表里面,我們也可以直接通過 update user 表來修改密碼。

 

  1. # 5.7及之后版本 
  2. mysql> update mysql.user set authentication_string = password ('Password4'where user = 'testuser' and host = '%'
  3. Query OK, 1 row affected, 1 warning (0.06 sec) 
  4. Rows matched: 1  Changed: 1  Warnings: 1 
  5.  
  6. mysql> flush privileges
  7. Query OK, 0 rows affected (0.01 sec) 
  8.  
  9. # 5.6及之前版本 
  10. 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 賬號在本地快捷登錄,可以這么做:

 

  1. # 執行回車后需要輸入一次root密碼 
  2. [root@host ~]# mysql_config_editor set --login-path=root -uroot  -hlocalhost -p -P3306  
  3. Enter password:  
  4.  
  5. # 配置完成后可以使用login-path登錄 
  6. [root@host ~]# mysql --login-path=root 
  7. Welcome to the MySQL monitor.  Commands end with ; or \g. 
  8. Your MySQL connection id is 2919 
  9. Server version: 5.7.23-log MySQL Community Server (GPL) 
  10.  
  11. Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. 
  12.  
  13. Oracle is a registered trademark of Oracle Corporation and/or its 
  14. affiliates. Other names may be trademarks of their respective 
  15. owners. 
  16.  
  17. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 
  18.  
  19. mysql>  

總結:

本篇文章主要介紹了修改數據庫賬號密碼的幾種方法,基本涵蓋了所有的場景。這里也提醒下各位,數據庫賬號最好限制ip段登錄,密碼盡量復雜些,最好能夠定期修改,特別是重要的環境不能有半點馬虎。年底了,安全才是王道。

責任編輯:華軒 來源: MySQL技術
相關推薦

2011-07-13 17:28:53

sa密碼SQL Server

2010-06-13 13:10:09

MySQLROOT密碼

2010-05-26 17:21:14

MySQL root密

2010-06-10 15:44:53

2020-10-20 08:01:30

MySQL密碼Windows

2015-05-26 08:46:58

密碼LaZagne Pro密碼檢索

2017-04-13 12:20:43

Mysqlroot密碼

2010-06-04 17:11:07

MySQLroot密碼

2010-04-20 16:46:41

Oracle數據庫密碼

2010-06-07 17:09:20

MySQLroot密碼

2010-06-04 16:03:37

MySQL root密

2010-04-23 13:53:29

Oracle密碼

2010-05-25 16:37:47

MySQL忘記密碼

2011-06-27 09:23:05

Ubuntu密碼

2010-10-14 10:09:33

MySQL root用

2009-06-27 14:11:17

2010-03-10 16:03:32

Linux省略密碼

2010-06-04 19:49:22

cnblogs

2011-05-19 09:58:26

2010-04-20 08:56:53

點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 欧美videosex性极品hd | 午夜视频在线 | 国产精品伦一区二区三级视频 | 天天综合国产 | 国产精品呻吟久久av凹凸 | 操操操av | 国产成人久久精品一区二区三区 | 色婷综合网| 中文字幕在线三区 | 污视频在线免费观看 | 国产乱性 | 色视频www在线播放国产人成 | 天天干天天插天天 | 国产日韩久久久久69影院 | 久久久噜噜噜www成人网 | 中文字幕一区在线 | 亚洲国产视频一区二区 | 精品欧美一区二区三区精品久久 | 色888www视频在线观看 | 精品一区二区久久久久久久网站 | 天天插天天狠天天透 | 99亚洲精品 | 国产无人区一区二区三区 | 伊人网在线看 | 在线不卡av| 日本一区二区视频 | 国产高清视频在线 | 亚洲国产一区在线 | 精品久久久久久久久久久 | 欧美成人第一页 | 国产99久久精品一区二区永久免费 | 亚洲a一区二区 | 国产成人精品亚洲日本在线观看 | 欧美精品电影一区 | 超碰高清| 亚洲精品中文字幕av | 久久久视| 草草草久久久 | 91精品国产综合久久国产大片 | 国产精品视频久久久 | 久久精品无码一区二区三区 |