Mysql-Mac安装(brew)


阅读次数

在Mac上可以直接通过 brew 工具进行安装

安装Mysql

brew install mysql

等待安装成功会提示信息如下:

We've installed your MySQL database without a root password. To secure it run:
mysql_secure_installation

To connect run:
mysql -uroot

A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.

To have launchd start mysql now and restart at login:
brew services start mysql
Or, if you don't want/need a background service you can just run:
mysql.server start



初始化root 密码

brew安装的mysql初始化是没有密码的,需要我们自定义,首先mysql.server start 启动mysql 的服务,然后执行 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?

# 是否确认设置密码插件
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: 2
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.
# For advice on how to change settings please see
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.

# 移除测试数据库
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 回车输入密码即可

">