Homebrew
Homebrew 是 macOS 系统自带的包管理器,类似于 CentOS 中的 yum
和 Ubuntu 的 apt-get
安装Homebrew
目前高版本的 macOS 系统中已经安装好了 Homebrew,输入
brew doctor复制代码
验证
如果你的系统没有安装,输入以下命令 安装Homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"复制代码
安装完成之后
- 输入
brew doctor
确认 brew 能正常工作 - 输入
brew update
更新包
安装 Cakebrew
Cakebrew 是 Homebrew 的一个图形化工具,可以更加直观对 Homebrew 进行管理,推荐安装
安装也很简单去 这个网站下载安装包进行安装就行了,软件自带中文。
接下来就可以愉快的玩耍了
安装软件时可能会遇到没有权限访问目录的问题,可以按照 Cakebrew 的提示在终端输入以下命令
sudo chown -R wqlm /usr/local/share/man/man8复制代码
- chown 命令是将 指定文件或目录的拥有者 改为指定的用户或组
- -R 是循环遍历 指定目录及子目录
- wqlm 是我系统的用户名
- /usr/local/share/man/man8 是被指定的目录
通过 Cakebrew 安装 mysql
安装 mysql 5.7
如图,输入你要安装的软件,选择其中一个,点击上方的安装按钮,就开始安装了,由于我已经安装了 msyql@5.7 所以上面显示的是卸载
配置 msyql 的环境变量
安装完之后我们需要配置 msyql 的环境变量
- 切换到用户目录下
cd ~
- 编辑 .bash_profile 配置文件
vi .bash_profile
- 输入
i
切换到编辑模式 - 输入
export PATH=/usr/local/opt/mysql@5.7/bin:$PATH
,/usr/local/opt/mysql@5.7/是你的安装目录 - 按下Esc输入
:wq
,保存并退出vi编辑器 - 输入
source .bash_profile
使配置立即生效
启动并初始化msyql
启动mysql服务
sudo mysql.server start
初始化mysql
sudo mysql_secure_installation
进入引导设置
Securing 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?# 上面的意思是说你十分要为root设置密码,选择 yPress y|Y for Yes, any other key for No: yThere are three levels of password validation policy:LOW Length >= 8MEDIUM Length >= 8, numeric, mixed case, and special charactersSTRONG Length >= 8, numeric, mixed case, special characters and dictionary file# 这里要你选一个密码强度等级,0表示LOW,只要求你的密码长度大于8,由于我只是在本地玩玩,选择0Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0Please set the password for root here.# 按照所选的密码强度要求 设定密码New password:# 再次输入密码Re-enter new password:Estimated strength of the password: 25Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y ... Failed! Error: Your password does not satisfy the current policy requirements# 如果你的密码没有满足 你所选的密码强度要求,它会让你重写设定密码New password:Re-enter new password:Estimated strength of the password: 100# 确认使用该密码吗,选择 yDo you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : yBy 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.# 删除默认的匿名用户吗,选择 yRemove 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.# 禁止远程root登录,我选的是no。因为我只是本地玩玩不会用于生产,也不会存什么敏感数据Disallow root login remotely? (Press y|Y for Yes, any other key for No) : no ... 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.# 要删除默认自带的test数据库吗,我选择 noRemove test database and access to it? (Press y|Y for Yes, any other key for No) : no - 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.# 是否让配置立即生效,选择 yReload privilege tables now? (Press y|Y for Yes, any other key for No) : ySuccess.All done!复制代码
设置完成之后,就可以通过 root 和刚刚设置的密码登陆mysql了
mysql -u root -p复制代码