MacOS下brew安装mysql5.7数据库

0.环境macOS Mojave 10.14.6
brew 安装方式
MySQL选择5.7版本

MacOS下brew安装mysql5.7数据库

文章插图
 
一、安装mysql5.7查询brew中mysql软件包:
? ~ brew search mysql
MacOS下brew安装mysql5.7数据库

文章插图
 
安装mysql5.7版本:
? ~ brew install mysql@5.7
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
mysql@5.7 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.
If you need to have mysql@5.7 first in your PATH run:
echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.zshrc
For compilers to find mysql@5.7 you may need to set:
export LDFLAGS="-L/usr/local/opt/mysql@5.7/lib"
export CPPFLAGS="-I/usr/local/opt/mysql@5.7/include"
To have launchd start mysql@5.7 now and restart at login:
brew services start mysql@5.7
Or, if you don't want/need a background service you can just run:
/usr/local/opt/mysql@5.7/bin/mysql.server start
安装过程如下:
MacOS下brew安装mysql5.7数据库

文章插图
 
二、设置环境变量? ~ vim .zshrc在文件最后添加:
#mysql5.7export PATH=/usr/local/opt/mysql@5.7/bin:$PATH然后按esc退出insert状态 , 并在最下方输入:wq保存退出 。
最后在刷新环境变量文件:
? ~ source ~/.zshrc三、启动mysql5.7brew安装的服务可以直接通过brew service start/stop来进行服务启停 , 如下:
# 启动 mysql, 并设置为开机启动brew services start mysql# 关闭 mysqlbrew services stop mysql# 重启 mysqlbrew services restart mysql但是 , 本次直接启动报错 , 如图:
MacOS下brew安装mysql5.7数据库

文章插图
【MacOS下brew安装mysql5.7数据库】 
明明之前安装了 , 为什么会报错呢?原因很简单 , 服务名不正确!
首先 , 查看正确的服务名:
? ~ brew services list显示正确的服务名应该是‘mysql@5.7’ , 所以 , 正确的启动服务命令为:
# 启动 mysql, 并设置为开机启动brew services start mysql@5.7# 关闭 mysqlbrew services stop mysql@5.7# 重启 mysqlbrew services restart mysql@5.7如图:
MacOS下brew安装mysql5.7数据库

文章插图
 
四、执行`mysql_secure_installation`进行安全加固主要涉及:
1.是否使用弱口令检查?
2.输入新密码;
3.是否移除匿名用户?
4.是否开启远程访问数据库连接权限?
5.是否删除`test`数据库?
6.刷新权限;
大家可以根据自己的情况进行设置 。
? ~ mysql_secure_installationSecuring the MySQL server deployment.Connecting to MySQL using a blank password.VALIDATE PASSWORD PLUGIN can be used to test passwordsand improve security. It checks the strength of passwordand allows the users to set only those passwords which aresecure enough. Would you like to setup VALIDATE PASSWORD plugin?Press y|Y for Yes, any other key for No: nPlease set the password for root here.New password:Re-enter new password:By default, a MySQL installation has an anonymous user,allowing anyone to log into MySQL without having to havea user account created for them. This is intended only fortesting, and to make the installation go a bit smoother.You should remove them before moving into a productionenvironment.Remove anonymous users? (Press y|Y for Yes, any other key for No) : ySuccess.Normally, root should only be allowed to connect from'localhost'. This ensures that someone cannot guess atthe root password from the network.Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n ... skipping.By default, MySQL comes with a database named 'test' thatanyone can access. This is also intended only for testing,and should be removed before moving into a productionenvironment.Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y - Dropping test database...Success. - Removing privileges on test database...Success.Reloading the privilege tables will ensure that all changesmade so far will take effect immediately.Reload privilege tables now? (Press y|Y for Yes, any other key for No) : ySuccess.All done!五、测试链接1.使用Navicat测试链接:
MacOS下brew安装mysql5.7数据库


推荐阅读