brew 安装mysql5.6_mac使用brew安装mysql的坑
## 記錄一次Mac上用brew安裝mysql遇到的坑 ##
brew安裝mysql的步驟:
brew search mysql 查看遠程倉庫中有哪些mysql的版本
選擇一個合適的mysql版本然后安裝它, brew install mysql
安裝好后,啟動mysql,如果不知道怎么啟動mysql,可以使用命令查看提示,brew info mysql,根據提示,有兩種啟動方式:brew services start mysql,或者 mysql.server start。
如果你使用brew services start mysql,會提示你沒有brew 沒有services命令,根據官網回復,發現這個命令從2014年就從brew的命令中移除了,原因是services的開源作者已經不再維護這個命令了,原文解釋鏈接。說實話,這個命令還是很好用的,只要記住軟件的名字,就能管理軟件的啟動、關閉,只可惜原作者不再維護倉庫了。
直接使用 mysql.server start 啟動mysql,會發現報錯了。
Starting MySQL
.. ERROR! The server quit without updating PID file (/usr/local/var/mysql/data/lingdeMacBook-Pro.local.pid).
然后網上一查這個報錯,清一色的回答就是這種答案列舉多種存在的原因,然后一試,全部方案發現都不行,還浪費時間。因為對mysql客戶端的安裝也沒經驗,病急亂投醫,一股腦子谷歌查解決方案。網上那種列舉多種存在原因的方式,不是說不好,但至少先科普一下有哪些標志性的癥狀導致的這種原因吧,不然像我們這種新手只能挨個試了。更可惡的是,全試之后,發現都無效,冷靜之后,突然想起自己也是個程序員啊,程序啟動不了出bug了,不會看日志嗎?
mysql日志文件在哪?在上面報錯提示中有寫:/usr/local/var/mysql/data/,進入該文件夾中,會看到有個文件是 .err 文件,我的是lingdeMacBook-Pro.local.err。
查看日志文件,cat lingdeMacBook-Pro.local.err,找到報錯的地方,如下
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
看到具體的報錯就好辦了,日志提示我使用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命令已經被丟棄了,不再使用mysql_upgrade進行更新mysql,oracle官網解釋,另外我發現我的mysql版本已經是最新的了,沒法更新,所以不是這個問題。只能再次查找萬能的google。
終于找到原因了,感謝這位博主的解釋-博文鏈接,就是說,mysql安裝后,需要手動進行初始化的操作。
使用mysql_install_db在 MySQL 服務器好后,在使用之前,必須執行的初始化任務:
它初始化 MySQL 數據目錄并創建它包含的系統表。
它初始化管理InnoDB表所需的系統表空間和相關數據結構。
它加載 server-side 幫助表。
它安裝sys schema。
它創建一個管理帳戶。
參考mysql5.7中文文檔的解釋,發現mysql_install_db命令在5.6之后就被廢棄了,使用新的初始化方式:mysqld --initialize --user=mysql
這時候可能還會報錯,如下:
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.
大概意思就是說,初始化的時候,/usr/local/var/mysql/data文件夾必須是空的,不能有任何文件,這好辦,直接刪除里面的文件,里面文件是mysql的數據文件:數據表文件、日志文件、索引文件等,如果是老數據庫一定要先備份數據庫之后才能重新初始化,否則數據會被全部刪除。刪除后,重新直接上面的初始化命令之后,重新啟動mysql。
mysql.server start,終于啟動成功了。
Starting MySQL
.. SUCCESS!
總結:對于一件完全沒有接觸或者不了解的問題,很多時候,第一想法就是,網上查找解決方案,因為沒有接觸,所以完全沒有能力分辨出網上的解決方案是否有效,所以只能挨個測試,這樣很浪費時間,并且有可能把電腦整出問題。在安裝的過程中,忘記了自己也是一名程序員,應該有排查bug的能力。時刻記著,在遇到問題時,不管有沒有接觸過,也要懂得使用自己掌握的能力去解決新問題!
總結
以上是生活随笔為你收集整理的brew 安装mysql5.6_mac使用brew安装mysql的坑的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: go interface 转int_大神
- 下一篇: mysql bandwidth_内存带宽