1、删除根目录下整个data文件夹(方便重新获取密码)
2、管理员权限打开cmd(必须以管理员权限!)
进入根目录
C:\Windows\system32>d:
D:>cd D:\mysql\mysql-8.0.15-winx64\bin
3、执行 net stop mysql 关闭mysql服务
4、根路径下bin下执行如下操作(mysqld --initialize --console)
D:\mysql\mysql-8.0.15-winx64\bin>mysqld --initialize --console
5、等待第四步生成密码,记下密码
这个是初始密码,复制出去待会儿要用 root@localhost: g8D+U=Idg(Gg(位置在下边代码cmd页面的倒数第二行结尾)
得到密码 g8D+U=Idg(Gg
2019-03-14T06:51:36.043507Z 0 [System] [MY-013169] [Server] D:\mysql\mysql-8.0.15-winx64\bin\mysqld.exe (mysqld 8.0.15) initializing of server in progress as process 9068
2019-03-14T06:51:36.043786Z 0 [ERROR] [MY-010338] [Server] Can’t find error-message file ‘D:\mysql-8.0.15-winx6in\share\errmsg.sys’. Check error-message file location and ‘lc-messages-dir’ configuration directive.
2019-03-14T06:51:36.044362Z 0 [Warning] [MY-013242] [Server] --character-set-server: ‘utf8’ is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2019-03-14T06:51:40.987103Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: g8D+U=Idg(Gg
2019-03-14T06:51:42.527624Z 0 [System] [MY-013170] [Server] D:\mysql\mysql-8.0.15-winx64\bin\mysqld.exe (mysqld 8.0.15) initializing of server has completed
6、开启mysql服务 net start mysql
7、输入 mysql -u root -p
Enter password:(将刚刚初始密码放这) 密码----> g8D+U=Idg(Gg
8、更改密码
mysql> alter user ‘root’@‘localhost’ identified with mysql_native_password by ‘admin’;
这里的 引号 复制过去如果是中文( 'root'@'localhost' 'admin' ),记得改成英文,同时 'root'@'localhost' 中的@复制过去有空隙的要让它们挨在一起,不然会报错,
Query OK, 0 rows affected (0.01 sec)
此时就成功了,用户为root 密码为admin
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit;
Bye
8、更改成功后,重输入自己的密码测试
D:\mysql\mysql-8.0.15-winx64\bin>mysql -u root -p
Enter password: *****
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.15 MySQL Community Server - GPL
Copyright © 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> show databases;
±-------------------+
| Database |
±-------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
±-------------------+
4 rows in set (0.01 sec)