mysql8.0.11安装成功后初始化临时密码报错
安装mysql8.0.11成功后查看mysql版本号
PS C:\WINDOWS\system32> mysql --version
C:\Software\mysql-8.0.11-winx64\bin\mysql.exe Ver 8.0.11 for Win64 on x86_64 (MySQL Community Server - GPL)
执行初始化命令mysqld --initialize --console报错
以管理员身份打开cmd进入到MySQL的bin目录,执行命令mysqld --initialize --console
命令mysqld --initialize --console的作用是使MySQL初始化并得到临时密码。
PS C:\Software\mysql-8.0.11-winx64\bin> mysqld --initialize --console
2018-10-31T03:18:05.201142Z 0 [System] [MY-013169] [Server] C:\Software\mysql-8.0.11-winx64\bin\mysqld.exe (mysqld 8.0.11) initializing of server in progress as process 2356
2018-10-31T03:18:05.231148Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2018-10-31T03:18:05.242682Z 0 [ERROR] [MY-010119] [Server] Aborting
2018-10-31T03:18:05.251312Z 0 [System] [MY-010910] [Server] C:\Software\mysql-8.0.11-winx64\bin\mysqld.exe: Shutdown complete (mysqld 8.0.11) MySQL Community Server - GPL.
出现报错
[ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
问题原因以及解决方法
mysql安装目录下data文件夹有数据,导致报错。
data文件夹的作用:
1、存放ibdata(所有数据库的信息都在这里);
2、存放数据库的文件夹,比如有个数据库叫teacher,那么会有个teacher文件夹,存放teacher数据库的所有文件。
解决办法:将data文件夹清空。
重新执行命令mysqld --initialize --console
PS C:\Software\mysql-8.0.11-winx64\bin> mysqld --initialize --console
2018-10-31T03:24:15.995649Z 0 [System] [MY-013169] [Server] C:\Software\mysql-8.0.11-winx64\bin\mysqld.exe (mysqld 8.0.11) initializing of server in progress as process 19760
2018-10-31T03:24:26.177747Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: #ld(EIl4XmA.
2018-10-31T03:24:31.063614Z 0 [System] [MY-013170] [Server] C:\Software\mysql-8.0.11-winx64\bin\mysqld.exe (mysqld 8.0.11) initializing of server has completed
得到临时密码#ld(EIl4XmA
使用临时密码登录MySQL并修改密码
输入命令 mysql -u root -p
PS C:\Software\mysql-8.0.11-winx64\bin> mysql -u root -p
Enter password: ************
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.11
Copyright (c) 2000, 2018, 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>
输入修改密码的SQL
mysql> alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.12 sec)
修改密码成功!