由于日常进数据库时都是记住密码,大家懂得!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