Table of Contents
Homebrew简介
Homebrew是一款自由及开放源代码的软件包管理系统,用以简化macOS系统上的软件安装过程,最初由马克斯·霍威尔写成。因其可扩展性得到了一致好评,并在Ruby on Rails社区广为人知。 Homebrew通过GitHub维护,并从其GitHub仓库中获取数据。用户可通过贡献此项目来增加支持的软件包。简而言之Homebrew 就是一个MacOS 系统的包管理器,类似于 CentOS 中的 yum 和 Ubuntu 的 apt-get。
安装Homebrew
目前高版本的MacOS 系统中已经安装好了 Homebrew,输入
brew doctor
进行验证,如果你的系统没有安装,输入以下命令安装Homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
安装完成之后输入brew doctor确认 brew 是否能正常工作,输入brew update 更新包。
Cakebrew简介
Cakebrew 是一款专门为 Homebrew 设计的图形化管理软件,可以更加直观对 Homebrew 进行管理。安装也很简单去 www.cakebrew.com 这个网站下载安装包进行安装就行了,软件自带中文。目前这款软件支持 Intel、Apple Silicon 两种架构,六国语言(含中英)。
安装Cakebrew
安装软件时可能会遇到没有权限访问目录的问题,可以按照 Cakebrew 的提示在终端输入以下命令:
sudo chown -R wqlm /usr/local/share/man/man8
使用Homebrew安装MySQL
如图,输入你要安装的软件,选择其中一个,点击上方的安装按钮就开始安装了,由于我已经安装了 msyql@5.7 所以上面显示的是卸载
配置MySQL环境变量
安装完之后我们需要配置 msyql 的环境变量,cd ~ 切换到用户目录下,编辑 .bash_profile 配置文件 vi .bash_profile,输入i 切换到编辑模式。在path中追加安装路径:
PATH=/usr/local/opt/mysql@5.7/bin:$PATH
其中/usr/local/opt/mysql@5.7/是你的安装目录,按下Esc输入:wq,保存并退出vi编辑器,输入source .bash_profile使配置立即生效。
启动并初始化MySQL
启动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 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? # 上面的意思是说你是否要为root设置密码,选择 y Press y|Y for Yes, any other key for No: y 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 # 这里要你选一个密码强度等级,0表示LOW,只要求你的密码长度大于8,由于我只是在本地玩玩,选择0 Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0 Please set the password for root here. # 按照所选的密码强度要求 设定密码 New password: # 再次输入密码 Re-enter new password: Estimated strength of the password: 25 Do 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 # 确认使用该密码吗,选择 y 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. # 删除默认的匿名用户吗,选择 y 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. # 禁止远程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' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. # 要删除默认自带的test数据库吗,我选择 no Remove 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 changes made so far will take effect immediately. # 是否让配置立即生效,选择 y Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y Success. All done!
设置完成之后,就可以通过 root 和刚刚设置的密码登陆mysql:
mysql -u root -p


评论(0)