1. 程式人生 > >Mac上通過 brew 安裝MySQL及其問題

Mac上通過 brew 安裝MySQL及其問題

一、環境和安裝

macOS 版本:10.13.1

Mysql 版本: mysql Ver 14.14 Distrib 5.7.20, for osx10.13 (x86_64) using EditLine wrapper

使用 brew 安裝 MySQL:

brew install mysql
brew tap homebrew/services
brew services start mysql

其他命令:

# 獲取 service 列表
brew services list
# 重啟 mysql 服務
brew services restart mysql
# 停止 mysql 服務
brew services stop mysql

二、碰到的問題

1、無法連線

描述:

使用 Navicat 或者是命令列都無法連線,均提示使用者名稱/密碼錯誤。

ERROR 1045 (28000) Access denied for user 'root'@'localhost' (using password: NO)

解決方法:

使用不要密碼登入:

sudo mysqld_safe --skip-grant-tables &

再使用下面指令碼重新設定下資料庫的 root 密碼:

UPDATE mysql.user SET authentication_string = PASSWORD('MyNewPass'
) WHERE User = 'root' AND Host = 'localhost';
FLUSH PRIVILEGES;

2、日誌裡面出現mysql 無法重啟啟動的錯誤日誌

日誌詳情:

Dec  6 01:36:35 --- last message repeated 1 time ---
Dec  6 01:36:35 s01 com.apple.xpc.launchd[1] (homebrew.mxcl.mysql[18960]): Service exited with abnormal code: 1
Dec  6 01:36:35 s01 com.apple.xpc.launchd
[1] (homebrew.mxcl.mysql): Service only ran for 0 seconds. Pushing respawn out by 10 seconds. Dec 6 01:36:45 s01 com.apple.xpc.launchd[1] (com.apple.xpc.launchd.domain.system): Session adoption is only allowed in user domains. Dec 6 01:36:45 --- last message repeated 1 time --- Dec 6 01:36:45 s01 com.apple.xpc.launchd[1] (homebrew.mxcl.mysql[19029]): Service exited with abnormal code: 1 Dec 6 01:36:45 s01 com.apple.xpc.launchd[1] (homebrew.mxcl.mysql): Service only ran for 0 seconds. Pushing respawn out by 10 seconds. Dec 6 01:36:55 s01 com.apple.xpc.launchd[1] (com.apple.xpc.launchd.domain.system): Session adoption is only allowed in user domains. Dec 6 01:36:55 --- last message repeated 1 time --- Dec 6 01:36:55 s01 com.apple.xpc.launchd[1] (homebrew.mxcl.mysql[19098]): Service exited with abnormal code: 1 Dec 6 01:36:55 s01 com.apple.xpc.launchd[1] (homebrew.mxcl.mysql): Service only ran for 0 seconds. Pushing respawn out by 10 seconds. Dec 6 01:37:06 s01 com.apple.xpc.launchd[1] (com.apple.xpc.launchd.domain.system): Session adoption is only allowed in user domains.

解決:

我查了下系統跑的有 mysql 程序(ps -e | grep mysql),也就是說出現了重複建立 mysql 服務。

檢視 macos 的自啟動服務列表:

ll ~/Library/LaunchAgents
ll /Library/LaunchDaemons
ll /Library/LaunchAgents

發現有重複的 mysql 服務,刪除掉重複的就是。

因為使用的是 brew services 方式執行,所以可以通過 brew services list來獲取正在執行的,把另外一個刪除了就行。

三、最後說2句

推薦使用 docker 方式,之前我使用的 mssql docker 版本就好安裝的多。

用了這麼久,mssql docker 偶爾會出現莫名其妙的閃退,而且也沒有發現日誌,疑惑!!!!。