MacOS下brew安装mysql5.7数据库

您所在的位置:网站首页 brew安装mysql MacOS下brew安装mysql5.7数据库

MacOS下brew安装mysql5.7数据库

2022-03-26 15:22| 来源: 网络整理| 查看: 265

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 [email protected]

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

[email protected] 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 [email protected] first in your PATH run:

echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc

For compilers to find [email protected] you may need to set:

export LDFLAGS="-L/usr/local/opt/[email protected]/lib"

export CPPFLAGS="-I/usr/local/opt/[email protected]/include"

To have launchd start [email protected] now and restart at login:

brew services start [email protected]

Or, if you don't want/need a background service you can just run:

/usr/local/opt/[email protected]/bin/mysql.server start

安装过程如下:

MacOS下brew安装mysql5.7数据库

 

二、设置环境变量 ➜ ~ vim .zshrc

在文件最后添加:

#mysql5.7 export PATH=/usr/local/opt/[email protected]/bin:$PATH

然后按esc退出insert状态,并在最下方输入:wq保存退出。

最后在刷新环境变量文件:

➜ ~ source ~/.zshrc 三、启动mysql5.7

brew安装的服务可以直接通过brew service start/stop来进行服务启停,如下:

# 启动 mysql, 并设置为开机启动 brew services start mysql # 关闭 mysql brew services stop mysql # 重启 mysql brew services restart mysql

但是,本次直接启动报错,如图:

MacOS下brew安装mysql5.7数据库

 

明明之前安装了,为什么会报错呢?原因很简单,服务名不正确!

首先,查看正确的服务名:

➜ ~ brew services list

显示正确的服务名应该是‘[email protected]’,所以,正确的启动服务命令为:

# 启动 mysql, 并设置为开机启动 brew services start [email protected] # 关闭 mysql brew services stop [email protected] # 重启 mysql brew services restart [email protected]

如图:

MacOS下brew安装mysql5.7数据库

 

四、执行`mysql_secure_installation`进行安全加固

主要涉及:

1.是否使用弱口令检查?

2.输入新密码;

3.是否移除匿名用户?

4.是否开启远程访问数据库连接权限?

5.是否删除`test`数据库?

6.刷新权限;

大家可以根据自己的情况进行设置。

➜ ~ 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: n Please 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 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) : 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) : y - Dropping test database... Success. - Removing privileges on test database... Success. 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) : y Success. All done! 五、测试链接

1.使用Navicat测试链接:

MacOS下brew安装mysql5.7数据库

 

2.使用命令行:

MacOS下brew安装mysql5.7数据库

 

六、设置开机启动

1.将/usr/local/opt/[email protected]/[email protected] 文件拷贝到~/Library/LaunchAgents目录下;

2.然后执行以下语句:

launchctl load -w ~/Library/LaunchAgents/[email protected]

注:这里的文件名以你mysql目录下的名字,或者你自己创建时起的名字为准

附:Mac OS X的启动原理:mac固件激活,初始化硬件,加载BootX引导器。BootX加载内核与内核扩展(kext)。内核启动launchd进程。launchd根据 /System/Library/LaunchAgents, /System/Library/LaunchDaemons , /Library/LaunchDaemons,/Library/LaunchAgents , ~/Library/LaunchAgents里的plist配置,启动服务守护进程。

[END]



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3