当先锋百科网

首页 1 2 3 4 5 6 7

mac 系统常用的软件安装工具就是 homebrew,如果你还不熟悉这个工具,请参考homebrew的使用

以下是我在安装mysql中所遇到的问题:

卸载

因为之前安装过一次,有很多问题,从新安装之前最好卸载掉原来的

$ brew remove mysql

$ brew cleanup

$ launchctl unload -w ~/Library/LaunchAgents/com.mysql.mysqld.plist

$ rm ~/Library/LaunchAgents/com.mysql.mysqld.plist

$ sudo rm -rf /usr/local/var/mysql

安装

$ brew install mysql

....

$ /usr/local/Homebrew/Library/Homebrew/brew.rb:12:in `': Homebrew must be run under Ruby 2.3! You're running 2.0.0. (RuntimeError)

此处报错了,提示Homebrew 必须在ruby2.3版本以上运行,而我现在的ruby版本是2.0,怎么办,只能升级ruby

如何升级ruby

mac下可以安装ruby的管理工具

$ curl -L get.rvm.io | bash -s stable

$ source /Users/你的用户名/.rvm/scripts/rvm

$ rvm -v

$ rvm list known

$ rvm install 2.4.1

$ ruby -v

再次执行 brew install mysql

==> Downloading https://homebrew.bintray.com/bottles/mysql-5.7.20.sierra.bottle.tar.gz

######################################################################## 100.0%

==> Pouring mysql-5.7.20.sierra.bottle.tar.gz

==> /usr/local/Cellar/mysql/5.7.20/bin/mysqld --initialize-insecure --user=shen --basedir

==> 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.server start

设置密码

mysqladmin -u root password 'xxx'

参考资料: