初始化mysql資料庫失敗的解決方法:先找到並開啟my.ini檔案;然後註解掉my.ini檔案中的datadir;最後根據提示把UTF8換成UTF8MB4即可。
推薦:《mysql影片教學》
安裝MySQL8,安裝時初始化資料庫失敗
大概過程
下載解壓縮到你想要安裝的目錄例如我這次是直接在C盤下。 C:\mysql-8.0.17-winx64
配置環境變量,把C:\mysql-8.0.17-winx64\bin加到PATH環境變數裡後邊即可注意“ ;」號
在C:\mysql-8.0.17-winx64這個目錄下新建my.ini檔。
寫my.ini檔案內容,內容容易出錯
#初始化資料庫,【我就是卡到這裡了】初始化成功的話或有MySQL的預設密碼
安裝資料庫
#啟動登入資料庫【第一次使用5中的預設密碼登入】
#修改密碼
在網路上查詢到一些教學作為參考,有一個解決方法是在一則評論裡看到的,找不到原部落格了,解決方法如下圖,是把datadir那一行給註解掉。
主要遇到的問題是,在my.ini檔案的編寫上,可能會有格式、內容上的錯誤,在格式上要注意「\」"\""/"都要試試,還有**“C:\mysql-8.0.17-winx64”** 是否加雙引號也試試看。以下是我的my.ini文件,大體內容與參考部落格相同,標出位置是我報錯之後修改的一些地方。
資料庫初始化時命令列出現的報錯如下:
C:\mysql-8.0.17-winx64\bin>mysqld --initialize --console 2019-08-24T13:33:22.622321Z 0 [System] [MY-013169] [Server] C:\mysql-8.0.17-winx64\bin\mysqld.exe (mysqld 8.0.17) initializing of server in progress as process 8404 2019-08-24T13:33:22.624188Z 0 [Warning] [MY-013243] [Server] --character-set-server: The character set UTF8MB3 is deprecated and will be removed in a future release. Please consider using UTF8MB4 instead. 2019-08-24T13:33:22.625619Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting. 2019-08-24T13:33:22.625635Z 0 [ERROR] [MY-013236] [Server] The designated data directory C:\mysql-8.0.17-winx64\data\ is unusable. You can remove all files that the server added to it. 2019-08-24T13:33:22.643590Z 0 [ERROR] [MY-010119] [Server] Aborting 2019-08-24T13:33:22.643744Z 0 [System] [MY-010910] [Server] C:\mysql-8.0.17-winx64\bin\mysqld.exe: Shutdown complete (mysqld 8.0.17) MySQL Community Server - GPL.
問題應該是data資料夾的問題,那時在C:\mysql-8.0.17-winx64目錄下根本就沒有新產生的data資料夾,註解掉my.ini檔案中datadir那一行初始化mysql的資料庫失敗怎麼辦就沒了,data資料夾也出現了,如下圖:
warring的解決辦法就根據其提示把UTF8換成UTF8MB4就行。改動地方均在上圖示註了出來。
2019-08-24T13:33:22.624188Z 0 [Warning] [MY-013243] [Server] --character-set-server: The character set UTF8 is deprecated and will be removed in a future release. Please consider using UTF8MB4 instead.
最後初始化成功,如圖:
總流程
C:\mysql-8.0.17-winx64\bin>mysqld --initialize --console 2019-08-24T13:37:11.590803Z 0 [System] [MY-013169] [Server] C:\mysql-8.0.17-winx64\bin\mysqld.exe (mysqld 8.0.17) initializing of server in progress as process 2484 2019-08-24T13:37:15.862830Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 37swG%65Qjf1 2019-08-24T13:37:17.783854Z 0 [System] [MY-013170] [Server] C:\mysql-8.0.17-winx64\bin\mysqld.exe (mysqld 8.0.17) initializing of server has completed C:\mysql-8.0.17-winx64\bin>mysqld --install The service already exists! The current server installed: C:\mysql-8.0.17-winx64\bin\mysqld.exe MySQL C:\mysql-8.0.17-winx64\bin>net start mysql MySQL 服务正在启动 . MySQL 服务已经启动成功。 C:\mysql-8.0.17-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.17 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> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '111111'; Query OK, 0 rows affected (0.01 sec) mysql>
以上是初始化mysql的資料庫失敗怎麼辦的詳細內容。更多資訊請關注PHP中文網其他相關文章!