1. 程式人生 > >重置mysql使用者密碼

重置mysql使用者密碼

又忘了資料庫root的密碼,還是記錄一下吧

重置 root 密碼
在忘記 root 密碼的情況下,可以進入 mysql 的安全模式,重置 root 密碼。

1. 停止 MySQL 服務

開啟命令提示符視窗,輸入 net stop mysql 關閉 MySQL 服務。

C:\Users\Administrator>net stop mysql57
MySQL57 服務正在停止..
MySQL57 服務已成功停止。

當然你也可以通過計算機管理面板關閉 MySQL 服務。

2. 切換到 bin 目錄

在命令提示符視窗中,通過 cd 命令切換到 mysql 安裝目錄下的 bin 目錄。

C:\Users\Administrator>
cd C:\Program Files\MySQL\MySQL Server 5.7\bin
C:\Program Files\MySQL\MySQL Server 5.7\bin>

↑ 預設安裝目錄為 C:\Program Files\MySQL\MySQL Server

3. 進入安全模式

在 bin 目錄下輸入 mysqld --skip-grant-tables ,跳過許可權檢查啟動 mysql。

如果你配置了 my.ini 檔案,則需要將其引入: mysqld --defaults-file="../my.ini" --skip-grant-tables

[mysqld]

basedir = "C:\ProgramData\MySQL\MySQL Server 5.7"
datadir = "C:\ProgramData\MySQL\MySQL Server 5.7\Data"

↑ 我在 my.ini 檔案中指定了資料的存放路徑,如果不引入配置檔案,則會提示 No such file or directory 錯誤。

4. 重置賬戶密碼

開啟另一個命令提示符視窗(別關閉安全模式視窗),同樣切換到 mysql \ bin 目錄,輸入 mysql 跳過許可權驗證連線資料庫。

C:\Program Files\MySQL\MySQL Server 5.7\bin>mysql
Server version: 5.7.16 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>

↑ 也可以指定連線引數 mysql -u <使用者名稱> -p <密碼> -h <連線地址> -P <埠號> -D <資料庫>

執行 update mysql.user set authentication_string="" where user="root"; 重置 root 使用者的密碼(5.7 之前為 password 欄位)。

mysql> update mysql.user set authentication_string="" where user="root";
Query OK, 1 row affected (0.00 sec)

mysql> select user,authentication_string from mysql.user\G
*************************** 1. row ***************************
         user: root
authentication_string:
*************************** 2. row ***************************
         user: mysql.sys
authentication_string: *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE

2 rows in set (0.00 sec)

↑ root 使用者的 authentication_string 欄位已經被清空了

5. 重新整理許可權表

執行 flush privileges; 命令重新整理許可權表,密碼已經重置完成,輸入 quit 退出。

mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)
mysql> quit
Bye

關閉所有命令提示符視窗,通過工作管理員結束 mysqld.exe 程序。重啟 MySQL 服務,之後就可以直接登入 root 賬號了。

修改 root 密碼

出於安全考慮,root 密碼不宜為空,所以需要在密碼重置之後,再重新設定一個密碼。

方法一:SET PASSWORD

SET PASSWORD FOR "username"=PASSWORD("new password");

以 root 身份登入 mysql,再使用 set password 命令修改密碼:

mysql> set password for [email protected] = password("pswd");
Query OK, 0 rows affected, 1 warning (0.00 sec)

方法二:mysqladmin

mysqladmin -u "username" -p password "new password"

執行該命名之後會提示輸入原密碼,輸入正確後即可修改。

C:\Program Files\MySQL\MySQL Server 5.7\bin> mysqladmin -u root -p password pswd
Enter password: ****

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.

方法三:UPDATE TABLE

UPDATE mysql.user SET authentication_string=PASSWORD("new password") WHERE user="username";

在重置 root 密碼的同時,也可以設定預設密碼。不過密碼不能為明文,必須使用 password() 函式加密。

mysql> update mysql.user set authentication_string=password("pswd") where user="root";
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

相關推薦

mysql root密碼

mysql1、用命令編輯/etc/my.cnf配置文件,即:vim /etc/my.cnf 或者 vi /etc/my.cnf2、在[mysqld]下添加skip-grant-tables,然後保存並退出3、重啟mysql服務:service mysqld restart4、重啟以後,執行mysql命令進入m

mac mysql 登入密碼

登入時報錯:解決Mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost'(using password: YSE) step1: 停止Mysql服務 step2: 進入終端輸入:cd /usr/local/mysq

MYSQL- Root密碼方法

方法一: 在my.ini的[mysqld]欄位加入: skip-grant-tables 重啟mysql服務,這時的mysql不需要密碼即可登入資料庫 然後進入mysql mysql>use mysql; mysql>更新 update user s

linuxmysql密碼

1.首先使用vim /etc/my.cnf進入此檔案按i進入編輯模式,在這裡回車加上這句話skip-grant-tables用來跳過密碼驗證 然後esc  輸入:wq儲存修改 2.重新啟動mysql 指令為:service mysqld restart 登入mysql&n

CentOSMySQL root密碼的方法

1.修改MySQL的登入設定: # vim /etc/my.cnf 在[mysqld]的段中加上一句:skip-grant-tables 例如: [mysqld] skip-grant-tables 儲存並且退出vi。 2.重新啟動mysqld # service mysqld restart Stoppi

mysql使用者密碼

又忘了資料庫root的密碼,還是記錄一下吧 重置 root 密碼 在忘記 root 密碼的情況下,可以進入 mysql 的安全模式,重置 root 密碼。 1. 停止 MySQL 服務 開啟命令提示符視窗,輸入 net stop mysql 關閉 MySQL 服務。

xampp集成環境下mysql密碼

狀態 flush mys roo 環境 table update console 第一步 第一步:打開兩個命令行工具,都進入到你的xampp安裝目錄下的mysql下的bin目錄,如我安裝的位置是D:xampp/mysql/bin; 第二步:在完成第一步的情況下,輸入:my

linux mysql 密碼

重啟 linu pass affect restart sta conn fff 改密 1.打開 p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Tahoma; color: #444444; background

mysql密碼

() chan 數據庫 expire 重置 ble 用戶登錄 rest etc 其實想要重置 5.7 的密碼很簡單,就一層窗戶紙: 1、修改 /etc/my.cnf,在 [mysqld] 小節下添加一行:skip-grant-tables=1 這一行配置讓 mysqld 啟

linux下mysql的root用戶密碼

linux學習如果忘記了MySQLroot密碼,可以用以下方法重新設置: 1.停掉系統裏的MySQL進程; killall-TERM mysqld 2.用以下命令啟動MySQL,以不檢查權限的方式啟動;進入到mysql的bin下 ./mysqld_safe--skip-grant-tables

centos下mysql密碼

centos首先我們要確認我們是在mysql啟動的狀態下輸入以下命令啟動mysql服務/etc/init.d/mysqld start然後輸入ps -ef | grep -i mysql可以看到mysqld_safe的安裝位置是/usr/bin/接下來我們停止mysql服務/etc/init.d/mysqld

Windows下MySQL密碼(最開始是因為Access denied for user 'root'@'localhost'這個原因,無法登陸 'root'@'localhost')

root 分享圖片 font 任務管理器 nts 技術分享 date 沒有 for 本人使用的MySQL5.5,其他版本未測試過。 1. 進入命令行窗口,停止MySQL服務 net stop mysql 2. 輸入mysqld --skip-grant-tab

MySQL的root密碼

mysq sta start 直接 amp ice 啟動mysql 服務 skip 停掉mysql服務: sudo /etc/init.d/mysqld stop 用安全模式啟動mysql: sudo mysqld_safe --skip-grant-tables &

XAMPPMySQL密碼

pda top current div class admin 登陸 and help   找到XAMPP的安裝位置,這裏以我的為例:C:\xampp   那麽MySQL的路徑:C:\xampp\mysql   phpMyAdmin的路徑:C:\xampp\phpMyA

Linux/Centos Mysql root用戶密碼

Mysql Linux Centos 系統 運維 有時候你可能會忘記MySQL的root用戶密碼,下面教你們重置MySQL root用戶密碼 手動修改 1、停止MySQL服務 執行:/etc/init.d/mysql stop,你的機器上也不一定是/etc/init.d/mysql也可能是

mysql登錄密碼

cmd upd 權限 pass 重啟 root -s ces use 1.停止mysql服務. services.msc進入服務界面 停止mysql服務 2.打開一個cmd窗口. 輸入mysqld --skip-grant-tables 啟動了一個新的mysql服務 跳過了

我來談談如何MySQL或MariaDB的Root密碼

images 其他 後臺運行 skip tables ges 步驟 因此 啟動 幾個月前,我在Ubuntu 18.04 上安裝了 LAMP。今天,我嘗試以 root 用戶身份登錄數據庫,但我完全忘記了密碼。經過一陣 Google 搜索並瀏覽一些文章後,我成功重置了密碼。對於

mysql root 使用者密碼

Linux下預設安裝了mysql,預設root使用者密碼為空。 於是設定了root使用者的密碼,使用了錯誤的命令如下: mysql> update user set password=123456 where user="ro

MySQL 8.0 以上版本 root 使用者密碼

MySQL 8.0 以上版本重置 root 使用者密碼 在 /etc/my.cnf 檔案末尾追加 skip-grant-tables [[email protected] mysql]# vim /etc/my.cnf [mysql] # 設定mysql客戶端預設字符集

MySQL 5.7 root使用者密碼

MySQL 5.7 重置root使用者密碼 注:MySQL 8.0 以上版本,請移步:MySQL 8.0 以上版本正確修改 root 密碼 cmd 切換到 mysql\bin 目錄下執行下面語句,用於跳過使用者驗證訪問資料庫(注:如果本機有正在執行的mysql的服務需要先停掉)