网上搜索了很多安装 Mac 的文章,基本上介绍安装的方法有官网下载安装包安装 和 homebrew 命令行安装,我选用的是命令行安装,mysql 的版本是 mysql Ver 8.0.12
参考链接:
- homebrew配置
- [Mac] 记录使用Homebrew安装Mysql全过程
- Mac上通过 brew 安装MySQL及其问题,这篇文章包含 brew services 的简单使用
- homebrew安装mysql及修改配置
- Mac下使用homebrew安装配置mysql
安装步骤如下:
- brew install
brew install mysql
- 等待安装完成之后,查看 mysql 版本号,显示版本信息,说明安装完成
mysql --version
- 开启 mysql 服务
brew services start mysql
或者也可以使用
mysql.server start
其他命令
brew services stop mysql
brew services restart mysql
- 设置密码
在安装之后,你会发现安装信息显示的是 We've installed your MySQL database without a root password. To secure it run: mysql_secure_installation,也就是安装的 mysql 没有设置密码,输入 mysql_secure_installation 设置密码,配置信息如下:
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD COMPONENT 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 component?
// 是否启用密码验证:y|Y 是 启用,其他按键 是 不启用
// 如果启用,密码长度会固定成 >=8,不想设置长密码的,可以选择不启用
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
// 启用 VALIDATE PASSWORD COMPONENT 之后,会进入密码强度的选择
// 密码强度:0 low;1 中等;2 强
// 接下来要设置密码要按照所选密码强度要求设置
// 没有启用 VALIDATE PASSWORD COMPONENT,会直接跳过这步,直接到下一步的密码设置,设置的密码也不用按照要求设置,可以设置 6 位密码等简单密码
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1
Please set the password for root here.
// 密码设置
New password:
// 再一次确认密码
Re-enter new password:
Estimated strength of the password: 50
// 再一次确认是否使用自己设置的密码
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
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.
// 取消远程 root 登录
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.
// 删除默认的 test 数据库
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!
- 登录
mysql -u root -p
Enter password: // 这里输入之前设置的密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.12 Homebrew
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>