在 Mac 下用 Homebrew 安裝 MySQL各類解決思路

常常不斷的遇到在mac上使用brew這個包管理神器安裝mysql出問題,今天在百度谷歌上搜索資料解決方案今天總算解決掉了,把這個解決方案分享出來mysql

個人系統是 Mac OS X 10.12,準備安裝的是 mysql 5.7.9
開始以前,假設你的brew已經安裝好並能夠使用。sql

安裝mysql,在終端輸入以下命令並回車:ui

brew install mysql

等待大概5分鐘(視網速而定)執行完畢後,會看到這一段提示:code

/usr/local/Cellar/mysql/5.7.9/bin/mysqld --initialize-insecure --user=comet
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

能夠看到brew在安裝的時候已經初始過mysql了(不用再像網上說的再執行mysql_install_db命令),且當前沒有密碼因而我按照它的提示,執行命令:orm

mysql_secure_installation

須要密碼時,直接回車,出現了以下的錯誤:server

Securing the MySQL server deployment.

Enter password for user root:
Error: Access denied for user 'root'@'localhost' (using password: NO)

啓動mysql服務的時候報錯ip

mysql.server start
Starting MySQL
... ERROR! The server quit without updating PID file (/usr/local/var/mysql/zhangzhingdeMBP.AirDream.pid).

在谷歌查詢了關於這個報錯PID文件的問題解決方案,執行下面的命令,(關於這個報錯能夠參考個人另一篇文章 )rem

sudo rm -rf /usr/local/var/mysql/dev.work.err (dev.work is my hostname)

而後再啓動mysql服務命令it

mysql.server start

提示 .SUCCESS!這時tmp目錄下有mysql.sock這個文件了,因而我繼續執行 mysql_secure_installationio

cometdeMacBook-Pro:~ comet$ mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: N   // 這個選yes的話密碼長度就必需要設置爲8位以上,但我只想要6位的
Please set the password for root here.

New password:            // 設置密碼

Re-enter new password:     // 再一次確認密碼
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y    // 移除不用密碼的那個帳戶
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n

 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!

OK!搞定,能夠使用mysql -u root -p 進行密碼鏈接了

PS:之後不再擔憂此類問題報錯了,媽媽不再擔憂我mysql安裝報錯了

相關文章
相關標籤/搜索