1. 程式人生 > >mysql8.0.11安裝成功後初始化臨時密碼報錯

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)

修改密碼成功!