一个简单的方式,利用homebrew
包管理工具,假设你已经安装了homebrew
命令行输入brew install mysql
过程可能会比较久,成功后会有如下提示
➜ blog brew install mysql
Updating Homebrew...
^C^[[A==> Downloading https://homebrew.bintray.com/bottles/mysql-5.7.20.high_sierra.bottle.tar.g
######################################################################## 100.0%
==> Pouring mysql-5.7.20.high_sierra.bottle.tar.gz
==> /usr/local/Cellar/mysql/5.7.20/bin/mysqld --initialize-insecure --user=liujinling --ba
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
mysql_secure_installation
MySQL is configured to only allow connections from localhost by default
To connect run:
mysql -uroot
To have launchd start mysql now and restart at login:
brew services start mysql
Or, if you don't want/need a background service you can just run:
mysql.server start
==> Summary
🍺 /usr/local/Cellar/mysql/5.7.20: 324 files, 233.7MB
根据绿色部分提示,我尝试mysql_secure_installation
,但是报错
➜ blog mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root:
Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
由于初次尝试,并不了解mysql,去网上搜了很多类似错误解决办法,都比较复杂。于是抱着试试看的心态回头试了下绿色提示最后一个建议brew services start mysql
➜ blog brew services start mysql
==> Tapping homebrew/services
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-services'...
remote: Enumerating objects: 17, done.
remote: Counting objects: 100% (17/17), done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 17 (delta 0), reused 13 (delta 0), pack-reused 0
Unpacking objects: 100% (17/17), done.
Tapped 0 formulae (49 files, 59.0KB)
==> Successfully started `mysql` (label: homebrew.mxcl.mysql)
看到Successfully着实安慰不小,接下来就该干嘛干嘛了,安装并启动成功!