Mac 10.15 使用brew安装mysql教程

1,284 阅读2分钟

@[TOC](Mac 10.15 使用brew安装mysql教程)

mysql安装步骤

系统说明

系统:macOS Catalina 10.15.7 内存:16G CPU: I3-6100 Homebrew 2.5.2

安装mysql

打开终端输入以下命令。

#安装mysql
brew install mysql

#设置mysql为开机启动项目
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents

#设置权限
sudo chmod -R 777 /usr/local/var/mysql/

启动mysql

终端输入启动指令

mysql.server start

初始化设置

运行初始化设置命令(设置密码等)

mysql_secure_installation

运行mysql_secure_installation会执行几个设置:

1、为root用户设置密码

2、删除匿名账号

3、取消root用户远程登录

4、删除test库和对test库的访问权限

5、刷新授权表使修改生效

执行代码如下:

var sugood$ 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设置
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
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: 50 
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远程登录,根据自己的需求选择Y/n并回车,建议禁止
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

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数据库,输入y删除
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : 

 ... skipping.
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) : 

 ... skipping.
All done! 

其他常用mysql指令

#进入Mysql
mysql -u[填写用户名] -p[填写密码]

#重启Mysql
mysql.server restart

#停止Mysql
mysql.server stop

#查看运行状态
mysql.server status