Mac下使用Homebrew安装MySql

Mac下使用Homebrew安装MySql

首先需要保证安装了Homebrew。

  • 安装MySql

$ brew install mysql

  • 设置MySql开机启动
$ mkdir -p ~/Library/LaunchAgents    # 首先确认该目录是否存在,若已经存在不用执行本命令  
$ ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents  
$ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
  • 启动MySql服务
$ mysql.server start  

错误修复
如果在启动过程中出现如下错误:ERROR! The server quit without updating PID file ,使用以下方法修复。

$ sudo chmod -R 755 /usr/local/var/mysql
$ rm -Rf /usr/local/var/mysql/Your-Machine-Name.local.err

注:将Your-Machine-Name替换为机器名称。

  • MySql安全性设置
$ mysql_secure_installation

Set root password? [Y/n] Y
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y  
  • 使用Homebrew卸载MySql
$ brew remove mysql
$ brew cleanup
$ launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
$ rm -Rf ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist  
Go Top
comments powered by Disqus