由於日常進數據庫時都是記住密碼,大家懂得!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
net stop mysql
cd
空格粘貼路徑mysqld --skip-grant-tables
回車。>
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