一、安装
1、执行安装命令
brew install mysql
2、安装完后启动mysql
mysql.server start
3、显示如下说明启动成功
Starting MySQL
. SUCCESS!
4、执行安全设置
mysql_secure_installation
显示如下
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
按照提示选择密码等级,并设置root密码
二、创建新的数据库、用户并授权
1、登录mysql
mysql -u root -p
按提示输入root密码
hehaowens-iMac:~ hehaowen$ mysql -u root -p
Enter password:
2、创建数据库
create database test_db character set utf8mb4;
3、创建用户
create user 'test_user'@'%' identified by 'test_pw';
4、授权用户
grant all privileges on test_db.* to 'test_user'@'%';
flush privileges;
5、查看当前的数据库
show databases;
6、显示当前数据库的表单
show tables
7、退出mysql
\q
三、检查mysql服务状态
输入命令
brew services list
显示如下结果说明mysql服务是正常的
Name Status User Plist
mysql stopped