MySQL 帳戶名與密碼修改!

Mac系統:

由於日常進數據庫時都是記住密碼,大家懂得!html

目前網上對於修改數據庫用戶名和密碼的方法太多了,如下爲我嘗試且成功的一種:mysql

NidhoggDJokingdeMacBook-Pro:~ joking$ cd /usr/local/mysql/bin/ 
NidhoggDJokingdeMacBook-Pro:bin joking$ ./mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.25 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.03 sec)

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('1234');
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> 複製代碼


PS:根據 MySQL 版本的不一樣,執行命令:sql

最開始沒注意有這個問題,仍是補充一下。數據庫

MySQL 5.7.6 and later: 
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass'; 

MySQL 5.7.5 and earlier: 
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');
複製代碼

  這裏是官方的文獻資料!
bash


Windows環境下:

不管在那個環境下切記最早關閉數據庫的服務!


  • DOS命令 net stop mysql

  • 轉到mysqlbin目錄

  • 能夠經過打開mysql應用快速找到mysqlbin目錄

  • 複製路徑而後在DOS裏輸入cd空格貼路徑

  • 輸入mysqld --skip-grant-tables回車。

  • 若是沒有出現提示信息,那就對了再開一個DOS窗口(剛纔那個DOS窗口已經不能動了),

  • 轉到mysqlbin目錄輸入mysql回車,若是成功,將出現MySQL提示符 >

  • 輸入FLUSH PRIVILEGES;(帶分號)

  • 輸入SET PASSWORD FOR 'root'@'localhost' = PASSWORD('1234');

  • 重啓服務net start mysql


Mysql程序在D盤:ui

C:\Users\Administrator>cd..

C:\Users>cd..

C:\>d:

D:\>
複製代碼

在進入mysql文件夾的bin目錄spa

相關文章
相關標籤/搜索