欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

MySQL修改密碼的幾種方式

 更新時(shí)間:2020年12月17日 14:32:10   作者:MySQL技術(shù)  
這篇文章主要介紹了MySQL修改密碼的幾種方式,幫助大家更好的理解和使用MySQL,感興趣的朋友可以了解下

前言:

在日常使用數(shù)據(jù)庫(kù)的過(guò)程中,難免會(huì)遇到需要修改賬號(hào)密碼的情景,比如密碼太簡(jiǎn)單需要修改、密碼過(guò)期需要修改、忘記密碼需要修改等。本篇文章將會(huì)介紹需要修改密碼的場(chǎng)景及修改密碼的幾種方式。

1.忘記 root 密碼

忘記 root 密碼的場(chǎng)景還是比較常見(jiàn)的,特別是自己搭的測(cè)試環(huán)境經(jīng)過(guò)好久沒(méi)用過(guò)時(shí),很容易記不得當(dāng)時(shí)設(shè)置的密碼。這個(gè)時(shí)候一般常用的方法是跳過(guò)權(quán)限驗(yàn)證,然后更改 root 密碼,之后再啟用權(quán)限驗(yàn)證。以 MySQL 5.7 版本為例簡(jiǎn)單講下主要過(guò)程:

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

# skip-grant-tables 模式下修改root密碼 
[root@host ~]# mysql 
Welcome to the MySQL monitor.  Commands end with ; or \g. 
Your MySQL connection id is 16 
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 mysql.user set authentication_string = password ('xxxxxx') where user = 'root' and host = 'localhost'; 
Query OK, 0 rows affected, 1 warning (0.00 sec) 
Rows matched: 1  Changed: 0  Warnings: 1 
 
mysql> flush privileges; 
Query OK, 0 rows affected (0.01 sec) 

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

2.幾種修改密碼的方法

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

使用 alter user 修改

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

mysql> alter user 'testuser'@'%' identified by 'Password1'; 
Query OK, 0 rows 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 賬號(hào)可修改其他賬號(hào)的密碼。

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 命令修改賬號(hào)密碼格式為 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 表

其實(shí) MySQL 所以的賬號(hào)信息都存儲(chǔ)在 mysql.user 表里面,我們也可以直接通過(guò) update user 表來(lái)修改密碼。

# 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.設(shè)置 login-path 本地快捷登陸

為了防止密碼暴露及忘記密碼,我們還可以設(shè)置 login-path 來(lái)實(shí)現(xiàn)在本地不輸密碼快捷登錄。

login-path 是 MySQL 5.6 開(kāi)始支持的新特性。通過(guò)借助 mysql_config_editor 工具將登陸 MySQL 服務(wù)的認(rèn)證信息加密保存在 .mylogin.cnf 文件(默認(rèn)位于用戶主目錄)。MySQL 客戶端工具可通過(guò)讀取該加密文件連接 MySQL ,實(shí)現(xiàn)快捷登錄。

假設(shè)我們想配置 root 賬號(hào)在本地快捷登錄,可以這么做:

# 執(zhí)行回車(chē)后需要輸入一次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>  

總結(jié):

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

以上就是MySQL修改密碼的幾種方式的詳細(xì)內(nèi)容,更多關(guān)于MySQL修改密碼的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Navicat for MySQL的使用教程詳解

    Navicat for MySQL的使用教程詳解

    本文給大家介紹Navicat for MySQL的使用教程,本文通過(guò)圖文實(shí)例相結(jié)合給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友跟隨小編一起學(xué)習(xí)下吧
    2021-05-05
  • MySQL replace函數(shù)替換字符串語(yǔ)句的用法

    MySQL replace函數(shù)替換字符串語(yǔ)句的用法

    MySQL replace函數(shù)我們經(jīng)常用到,下面就為您詳細(xì)介紹MySQL replace函數(shù)的用法,希望對(duì)您學(xué)習(xí)MySQL replace函數(shù)方面能有所啟迪。
    2010-12-12
  • SQL查詢語(yǔ)句優(yōu)化的實(shí)用方法總結(jié)

    SQL查詢語(yǔ)句優(yōu)化的實(shí)用方法總結(jié)

    下面小編就為大家?guī)?lái)一篇SQL查詢語(yǔ)句優(yōu)化的實(shí)用方法總結(jié)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2016-12-12
  • MySQL與MSSQl使用While語(yǔ)句循環(huán)生成測(cè)試數(shù)據(jù)的代碼

    MySQL與MSSQl使用While語(yǔ)句循環(huán)生成測(cè)試數(shù)據(jù)的代碼

    有時(shí)候我們測(cè)試性能的時(shí)候經(jīng)常需要生產(chǎn)大量的測(cè)試數(shù)據(jù),用sql語(yǔ)句直接生成的數(shù)據(jù)更快,需要的朋友可以參考下。
    2010-12-12
  • 詳解MySQL如何交換兩列值數(shù)據(jù)

    詳解MySQL如何交換兩列值數(shù)據(jù)

    最近遇到了需要將表里的兩列值進(jìn)行互換,原因是存庫(kù)時(shí)值存放反了,在編碼語(yǔ)言中,我們一般可以通過(guò)定義一個(gè)臨時(shí)變量c,將b賦值給c,a賦值給b,c賦值給a就能實(shí)現(xiàn)a和b的值互換,那么,在mysql中,非儲(chǔ)存過(guò)程的sql語(yǔ)句,沒(méi)有定義變量的過(guò)程,如何實(shí)現(xiàn)呢,接下來(lái)由小編給大家介紹一下
    2024-01-01
  • MySQL?8.0新功能監(jiān)控統(tǒng)計(jì)限制連接不再擔(dān)心被垃圾SQL搞爆內(nèi)存

    MySQL?8.0新功能監(jiān)控統(tǒng)計(jì)限制連接不再擔(dān)心被垃圾SQL搞爆內(nèi)存

    這篇文章主要介紹了MySQL?8.0新功能監(jiān)控統(tǒng)計(jì)限制連接不再擔(dān)心被垃圾SQL搞爆內(nèi)存詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-05-05
  • MySQL如何建表及導(dǎo)出建表語(yǔ)句

    MySQL如何建表及導(dǎo)出建表語(yǔ)句

    這篇文章主要介紹了MySQL如何建表及導(dǎo)出建表語(yǔ)句,文章圍繞主題的相關(guān)資料展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下
    2022-05-05
  • Mysql中Identity 詳細(xì)介紹

    Mysql中Identity 詳細(xì)介紹

    這篇文章主要介紹了Mysql中Identity 的相關(guān)資料,并附示例代碼,需要的朋友可以參考下
    2016-09-09
  • 詳解Mysql 30條軍規(guī)

    詳解Mysql 30條軍規(guī)

    這篇文章主要介紹了詳解Mysql 30條軍規(guī),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-08-08
  • MySQL為何不建議使用默認(rèn)值為null列

    MySQL為何不建議使用默認(rèn)值為null列

    本文主要介紹了MySQL為何不建議使用默認(rèn)值為null列,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-08-08

最新評(píng)論