请选择 进入手机版 | 继续访问电脑版
查看: 856|回复: 0

[Mysql数据库] os x 10.10.5下用brew安装mysql

3万

主题

3万

帖子

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
100167
发表于 2015-12-2 18:44:47

os x 10.10.5下用brew安装mysql,有需要的朋友可以参考下。


homebrew是mac下一个很好的包管理器,通过它安装一些软件很方便,而且便于管理。虽然MySQL官方提供了mac的安装包,但我还是习惯于用brew安装mysql。

Taps

因为brew是从github下载的软件包,所以可能会很慢,我这里是用的ss+proxychains-ng强制brew使用socks5代理的。关于proxychains-ng的具体用法我这里最不赘述了。

准备工作

首先brew serach mysql,搜索到很多mysql相关的包:

  1. automysqlbackup mysql mysql-sandbox
  2. groonga-normalizer-mysql mysql++ mysql-search-replace
  3. homebrew/versions/mysql51 mysql-cluster mysqltuner
  4. homebrew/versions/mysql55 mysql-connector-c
  5. homebrew/versions/mysql56 mysql-connector-c++
  6. homebrew/php/php53-mysqlnd_ms homebrew/php/php56-mysqlnd_ms
  7. homebrew/php/php54-mysqlnd_ms Caskroom/cask/mysqlworkbench
  8. homebrew/php/php55-mysqlnd_ms Caskroom/cask/navicat-for-mysql
复制代码

因为我需要做C语言连接mysql,所以只需要安装mysql。

安装mysql

直接执行brew install mysql,如果需要使用proxychains-ng,就用proxychains4 brew install mysql,接下来就等mysql安装好了,可是事情并没有那么顺利。

安装过程中提示错误:

  1. Error: The 'brew link' step did not complete successfully
  2. The formula built, but is not symlinked into /usr/local
  3. Could not symlink share/man/man8/mysqld.8
  4. /usr/local/share/man/man8 is not writable.
  5. You can try again using:
  6. brew link mysql
复制代码

当我使用brew link mysql建立mysql软连接的时候出现同样的错误。看错误的提示大概就是/usr/local/share/man/man8 is not writable这个目录不可写,这样的话就简单了。

执行brew doctor发现

  1. Warning: Some directories in /usr/local/share/man aren't writable.
  2. This can happen if you "sudo make install" software that isn't managed
  3. by Homebrew. If a brew tries to add locale information to one of these
  4. directories, then the install will fail during the link step.
  5. You should probably `sudo chown -R $(whoami)` them:
  6. /usr/local/share/man/man8
复制代码

接着执行sudo chown -R $(whoami) /usr/local/share/man/man8,完美解决问题。

再brew link mysql成功,mysql相关的各种命令都已经链接到了/usr/local/bin目录下。

需要注意的是,brew最后输出的一段话:

  1. We've installed your MySQL database without a root password. To secure it run:
  2. mysql_secure_installation
  3. To connect run:
  4. mysql -uroot
  5. To have launchd start mysql at login:
  6. ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
  7. Then to load mysql now:
  8. launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
  9. Or, if you don't want/need launchctl, you can just run:
  10. mysql.server start
复制代码
安全设置向导

需要注意的是,安装好得mysql是没有root密码的,需要自己设置root密码。

首先启动mysql,mysql.server start,然后设置数据库访问权限,
mysql_secure_installation

  1. Securing the MySQL server deployment.
  2. Connecting to MySQL using a blank password.
  3. VALIDATE PASSWORD PLUGIN can be used to test passwords
  4. and improve security. It checks the strength of password
  5. and allows the users to set only those passwords which are
  6. secure enough. Would you like to setup VALIDATE PASSWORD plugin?
  7. Press y|Y for Yes, any other key for No: y <-是否使用VALIDATE PASSWORD PLUGIN,这个看自己了
  8. There are three levels of password validation policy:
  9. LOW Length >= 8
  10. MEDIUM Length >= 8, numeric, mixed case, and special characters
  11. STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
  12. Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1(这里我选了1,即MEDIUM,密码需要有大小写字母、数字、特殊符号)
  13. Please set the password for root here.
  14. New password: (输入你的密码)
  15. Re-enter new password: (再次输入你的密码)
  16. Estimated strength of the password: 100
  17. Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
  18. By default, a MySQL installation has an anonymous user,
  19. allowing anyone to log into MySQL without having to have
  20. a user account created for them. This is intended only for
  21. testing, and to make the installation go a bit smoother.
  22. You should remove them before moving into a production
  23. environment.
  24. Remove anonymous users? (Press y|Y for Yes, any other key for No) : y(是否删除匿名用户,生产环境建议删除)
  25. Success.
  26. Normally, root should only be allowed to connect from
  27. 'localhost'. This ensures that someone cannot guess at
  28. the root password from the network.
  29. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : (是否禁止root远程登录,根据自己的需求选择Y/n并回车,建议禁止)
  30. ... skipping.
  31. By default, MySQL comes with a database named 'test' that
  32. anyone can access. This is also intended only for testing,
  33. and should be removed before moving into a production
  34. environment.
  35. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : (是否删除test数据库,直接回车)
  36. ... skipping.
  37. Reloading the privilege tables will ensure that all changes
  38. made so far will take effect immediately.
  39. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : (是否重新加载权限表,直接回车)
  40. ... skipping.
  41. All done! ```
复制代码

如果想设置mysql开机启动:
To have launchd start mysql at login:
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
Then to load mysql now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
如果想自己手动启动
Or, if you don’t want/need launchctl, you can just run:
mysql.server start



回复

使用道具 举报