一、安装homebrew
homebrew是macOS缺失的软件包管理器,譬如可以下载mysql、maven等等。
安装方法:
/usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”
将以上命令粘贴至终端。
homebrew更多详情请查看官网: https://brew.sh/index_zh-cn.html
二、安装mysql
$ brew instal mysql
其中运行mysql_secure_installation 可以设置密码
运行brew service start mysql 可以后台启动mysql
运行mysql.server start 前台启动mysql(关闭控制台,服务停止)
三、下载完成后启动mysql
$ mysql.server start
四、更改密码
mysql_secure_installation
**
下面的内容除了写密码,其它全部选y也不会有太大的问题
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?
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
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1(选择密码强度等级)
等级1的密码组成为:数字、混合大小写和特殊字符
Please set the password for root here.
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登录,我选的是不禁止。因为我的mac上的数据库不会放到公网上,也不会存什么敏感数据
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数据库
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
六、退出
mysql>quit;
最后注意一点:
如果提示权限问题使用sudo指令,我的笔记本上如果不加此指令各种权限问题