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相关的包:

automysqlbackup            mysql         mysql-sandbox            
groonga-normalizer-mysql   mysql++                    mysql-search-replace     
homebrew/versions/mysql51  mysql-cluster              mysqltuner               
homebrew/versions/mysql55  mysql-connector-c        
homebrew/versions/mysql56  mysql-connector-c++      
homebrew/php/php53-mysqlnd_ms            homebrew/php/php56-mysqlnd_ms          
homebrew/php/php54-mysqlnd_ms            Caskroom/cask/mysqlworkbench           
homebrew/php/php55-mysqlnd_ms            Caskroom/cask/navicat-for-mysql 

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

安装mysql

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

安装过程中提示错误:

Error: The 'brew link' step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink share/man/man8/mysqld.8
/usr/local/share/man/man8 is not writable.

You can try again using:
    brew link mysql

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

执行brew doctor发现

Warning: Some directories in /usr/local/share/man aren't writable.
This can happen if you "sudo make install" software that isn't managed
by Homebrew. If a brew tries to add locale information to one of these
directories, then the install will fail during the link step.

You should probably `sudo chown -R $(whoami)` them:
    /usr/local/share/man/man8

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

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

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

    We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

To connect run:
    mysql -uroot

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

安全设置向导

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

首先启动mysql,mysql.server start,然后设置数据库访问权限,
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: y <-是否使用VALIDATE PASSWORD PLUGIN,这个看自己了

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1(这里我选了1,即MEDIUM,密码需要有大小写字母、数字、特殊符号)
Please set the password for root here.

New password: (输入你的密码)
Re-enter new password: (再次输入你的密码)

Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
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) : (是否禁止root远程登录,根据自己的需求选择Y/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) : (是否删除test数据库,直接回车)

 ... skipping.
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) : (是否重新加载权限表,直接回车)

 ... skipping.
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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值