brew 安装mysql5.6_mac使用brew安装mysql的坑
## 記錄一次Mac上用brew安裝mysql遇到的坑 ##
brew安裝mysql的步驟:
brew search mysql 查看遠(yuǎn)程倉(cāng)庫(kù)中有哪些mysql的版本
選擇一個(gè)合適的mysql版本然后安裝它, brew install mysql
安裝好后,啟動(dòng)mysql,如果不知道怎么啟動(dòng)mysql,可以使用命令查看提示,brew info mysql,根據(jù)提示,有兩種啟動(dòng)方式:brew services start mysql,或者 mysql.server start。
如果你使用brew services start mysql,會(huì)提示你沒(méi)有brew 沒(méi)有services命令,根據(jù)官網(wǎng)回復(fù),發(fā)現(xiàn)這個(gè)命令從2014年就從brew的命令中移除了,原因是services的開(kāi)源作者已經(jīng)不再維護(hù)這個(gè)命令了,原文解釋鏈接。說(shuō)實(shí)話,這個(gè)命令還是很好用的,只要記住軟件的名字,就能管理軟件的啟動(dòng)、關(guān)閉,只可惜原作者不再維護(hù)倉(cāng)庫(kù)了。
直接使用 mysql.server start 啟動(dòng)mysql,會(huì)發(fā)現(xiàn)報(bào)錯(cuò)了。
Starting MySQL
.. ERROR! The server quit without updating PID file (/usr/local/var/mysql/data/lingdeMacBook-Pro.local.pid).
然后網(wǎng)上一查這個(gè)報(bào)錯(cuò),清一色的回答就是這種答案列舉多種存在的原因,然后一試,全部方案發(fā)現(xiàn)都不行,還浪費(fèi)時(shí)間。因?yàn)閷?duì)mysql客戶端的安裝也沒(méi)經(jīng)驗(yàn),病急亂投醫(yī),一股腦子谷歌查解決方案。網(wǎng)上那種列舉多種存在原因的方式,不是說(shuō)不好,但至少先科普一下有哪些標(biāo)志性的癥狀導(dǎo)致的這種原因吧,不然像我們這種新手只能挨個(gè)試了。更可惡的是,全試之后,發(fā)現(xiàn)都無(wú)效,冷靜之后,突然想起自己也是個(gè)程序員啊,程序啟動(dòng)不了出bug了,不會(huì)看日志嗎?
mysql日志文件在哪?在上面報(bào)錯(cuò)提示中有寫(xiě):/usr/local/var/mysql/data/,進(jìn)入該文件夾中,會(huì)看到有個(gè)文件是 .err 文件,我的是lingdeMacBook-Pro.local.err。
查看日志文件,cat lingdeMacBook-Pro.local.err,找到報(bào)錯(cuò)的地方,如下
2020-04-19T15:32:03.348611Z 0 [Note] InnoDB: 5.7.29 started; log sequence number 0
2020-04-19T15:32:03.361731Z 0 [Note] Plugin 'FEDERATED' is disabled.
mysqld: Table 'mysql.plugin' doesn't exist
2020-04-19T15:32:03.397132Z 0 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
2020-04-19T15:32:03.457609Z 0 [ERROR] unknown variable 'mysqlx-bind-address=127.0.0.1'
2020-04-19T15:32:03.457784Z 0 [ERROR] Aborting
看到具體的報(bào)錯(cuò)就好辦了,日志提示我使用mysql_upgrade更新mysql版本,以為終于能搞定了,按耐不住的心情趕緊照做,然而我還是太年輕了。
mysql_upgrade --protocol=tcp -P3306 -p,提示如下
The mysql_upgrade client is now deprecated. The actions executed by the upgrade client are now done by the server.
To upgrade, please start the new MySQL binary with the older data directory. Repairing user tables is done automatically. Restart is not required after upgrade.
The upgrade process automatically starts on running a new MySQL binary with an older data directory. To avoid accidental upgrades, please use the --upgrade=NONE option with the MySQL binary. The option --upgrade=FORCE is also provided to run the server upgrade sequence on demand.
It may be possible that the server upgrade fails due to a number of reasons. In that case, the upgrade sequence will run again during the next MySQL server start. If the server upgrade fails repeatedly, the server can be started with the --upgrade=MINIMAL option to start the server without executing the upgrade sequence, thus allowing users to manually rectify the problem.
大概意思就是mysql_upgrade命令已經(jīng)被丟棄了,不再使用mysql_upgrade進(jìn)行更新mysql,oracle官網(wǎng)解釋,另外我發(fā)現(xiàn)我的mysql版本已經(jīng)是最新的了,沒(méi)法更新,所以不是這個(gè)問(wèn)題。只能再次查找萬(wàn)能的google。
終于找到原因了,感謝這位博主的解釋-博文鏈接,就是說(shuō),mysql安裝后,需要手動(dòng)進(jìn)行初始化的操作。
使用mysql_install_db在 MySQL 服務(wù)器好后,在使用之前,必須執(zhí)行的初始化任務(wù):
它初始化 MySQL 數(shù)據(jù)目錄并創(chuàng)建它包含的系統(tǒng)表。
它初始化管理InnoDB表所需的系統(tǒng)表空間和相關(guān)數(shù)據(jù)結(jié)構(gòu)。
它加載 server-side 幫助表。
它安裝sys schema。
它創(chuàng)建一個(gè)管理帳戶。
參考mysql5.7中文文檔的解釋,發(fā)現(xiàn)mysql_install_db命令在5.6之后就被廢棄了,使用新的初始化方式:mysqld --initialize --user=mysql
這時(shí)候可能還會(huì)報(bào)錯(cuò),如下:
2020-04-19T16:27:20.161959Z 0 [System] [MY-013169] [Server] /usr/local/Cellar/mysql/8.0.19/bin/mysqld (mysqld 8.0.19) initializing of server in progress as process 57630
2020-04-19T16:27:20.170544Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2020-04-19T16:27:20.170568Z 0 [ERROR] [MY-013236] [Server] The designated data directory /usr/local/var/mysql/data/ is unusable. You can remove all files that the server added to it.
2020-04-19T16:27:20.170649Z 0 [ERROR] [MY-010119] [Server] Aborting
2020-04-19T16:27:20.173505Z 0 [System] [MY-010910] [Server] /usr/local/Cellar/mysql/8.0.19/bin/mysqld: Shutdown complete (mysqld 8.0.19) Homebrew.
大概意思就是說(shuō),初始化的時(shí)候,/usr/local/var/mysql/data文件夾必須是空的,不能有任何文件,這好辦,直接刪除里面的文件,里面文件是mysql的數(shù)據(jù)文件:數(shù)據(jù)表文件、日志文件、索引文件等,如果是老數(shù)據(jù)庫(kù)一定要先備份數(shù)據(jù)庫(kù)之后才能重新初始化,否則數(shù)據(jù)會(huì)被全部刪除。刪除后,重新直接上面的初始化命令之后,重新啟動(dòng)mysql。
mysql.server start,終于啟動(dòng)成功了。
Starting MySQL
.. SUCCESS!
總結(jié):對(duì)于一件完全沒(méi)有接觸或者不了解的問(wèn)題,很多時(shí)候,第一想法就是,網(wǎng)上查找解決方案,因?yàn)闆](méi)有接觸,所以完全沒(méi)有能力分辨出網(wǎng)上的解決方案是否有效,所以只能挨個(gè)測(cè)試,這樣很浪費(fèi)時(shí)間,并且有可能把電腦整出問(wèn)題。在安裝的過(guò)程中,忘記了自己也是一名程序員,應(yīng)該有排查bug的能力。時(shí)刻記著,在遇到問(wèn)題時(shí),不管有沒(méi)有接觸過(guò),也要懂得使用自己掌握的能力去解決新問(wèn)題!
總結(jié)
以上是生活随笔為你收集整理的brew 安装mysql5.6_mac使用brew安装mysql的坑的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: go interface 转int_大神
- 下一篇: mysql bandwidth_内存带宽