朋友們大家好,在這篇文章中我想分享一個(gè)處理 mysql 8.0 的教程,當(dāng)你升級到 mysql 8.0 時(shí),該教程將不會啟動
發(fā)生的錯(cuò)誤
好吧,當(dāng)我在 laragon 應(yīng)用程序中從mysql 5.1.72升級到mysql 8.0.32時(shí),發(fā)生了這個(gè)錯(cuò)誤。
當(dāng)我在 laragon 應(yīng)用程序中 start all 時(shí),出現(xiàn)的錯(cuò)誤是這樣的。
laragon 中的 mysql 8.0 錯(cuò)誤
然后我檢查了位于c:laragondatamysql-8mysqld.log的日志文件
在那里我發(fā)現(xiàn)了如下錯(cuò)誤
mysqld: table 'mysql.plugin' doesn't exist 2023-02-16t23:34:54.041942z 0 [error] [my-010735] [server] could not open the mysql.plugin table. please perform the mysql upgrade procedure.
登錄后復(fù)制
除此之外,我還發(fā)現(xiàn)了這樣的錯(cuò)誤
2023-02-16t23:34:54.460889z 0 [error] [my-010326] [server] fatal error: can't open and lock privilege tables: table 'mysql.user' doesn't exist 2023-02-16t23:34:54.462984z 0 [error] [my-010952] [server] the privilege system failed to initialize correctly. for complete instructions on how to upgrade mysql to a new version please see the 'upgrading mysql' section from the mysql manual.
登錄后復(fù)制
從這個(gè)錯(cuò)誤可以明顯看出我所做的升級過程是錯(cuò)誤的。 錯(cuò)誤是我沒有先初始化mysql 8.0,所以mysql 8.0找不到我需要的表.
解決方案:初始化mysql
好的,所以我們要做的解決方案是先啟動mysql 8.0,然后再啟動mysql服務(wù)器。
在 windows 中打開命令提示符,然后運(yùn)行以下命令
mysqld --initialize-insecure
登錄后復(fù)制
其實(shí)有2個(gè)選項(xiàng),第一個(gè)使用–initialize,第二個(gè)–initialize-insecure。唯一的區(qū)別是 root 帳戶的密碼。第一個(gè)選項(xiàng)將生成一個(gè)臨時(shí)隨機(jī)密碼。對于第二個(gè)選項(xiàng),root賬戶沒有密碼,但是稍后我們可以為root設(shè)置密碼。
好了,啟動mysql 8.0的過程就完成了,到這里應(yīng)該就可以啟動mysql 8.0或者服務(wù)器可以正常運(yùn)行了。
更改根密碼
因?yàn)槲覀兪褂昧说诙€(gè)選項(xiàng),這意味著 root 帳戶沒有密碼,因此無需使用密碼即可輕松訪問。如果是在本地電腦上也還可以,因?yàn)閣eb開發(fā)需求也更快
但是如果朋友想為root賬戶添加密碼,也很簡單
首先運(yùn)行以下命令進(jìn)入mysql命令行。
mysql -u root
登錄后復(fù)制
登錄后,運(yùn)行以下命令。不要忘記最后一個(gè)分號。
alter user 'root'@'localhost' identified by 'password_baru_untuk_root';
登錄后復(fù)制
將 new_password_for_root 更改為您想要的密碼。然后進(jìn)入。
現(xiàn)在運(yùn)行命令exit退出mysql命令行。然后運(yùn)行以下命令。然后輸入您之前創(chuàng)建的新密碼。
mysql -u root -p
登錄后復(fù)制
祝你嘗試順利 ?