美文网首页
mac通过Homebrew安装mysql

mac通过Homebrew安装mysql

作者: rogerslin | 来源:发表于2019-12-07 21:22 被阅读0次

安装Homebrew后,控制台输入命令(这里安装mysql 5.7版本):

$ brew install mysql@5.7
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/cask).
No changes to formulae.

==> Downloading https://homebrew.bintray.com/bottles/mysql@5.7-5.7.28.catalina.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/25/25979cdf7664ceabbe69c4423317612e51cb2dc73d4e5cb4e24abefc29aa018a?__gda__=exp=1575720818~hmac
######################################################################## 100.0%
==> Pouring mysql@5.7-5.7.28.catalina.bottle.tar.gz
==> /usr/local/Cellar/mysql@5.7/5.7.28/bin/mysqld --initialize-insecure --user=yuanlin --basedir=/usr/local/Cellar/mysql@5.7/5.7.28 --datadir=/
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
    mysql -uroot

mysql@5.7 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have mysql@5.7 first in your PATH run:
  echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.zshrc
// 执行上面这个命令将mysql加入PATH

For compilers to find mysql@5.7 you may need to set:
  export LDFLAGS="-L/usr/local/opt/mysql@5.7/lib"
  export CPPFLAGS="-I/usr/local/opt/mysql@5.7/include"


To have launchd start mysql@5.7 now and restart at login:
  brew services start mysql@5.7
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/mysql@5.7/bin/mysql.server start
==> Summary
🍺  /usr/local/Cellar/mysql@5.7/5.7.28: 319 files, 232.2M
$

安装完毕,可以通过下面这个命令直接启动mysql:

$ mysql.server start

也可以通过服务方式启动:

$ brew services start mysql@5.7

如第一步安装过程中输出的提示所述,现在还没有设置root密码,要通过下面这个命令进行设置:

$ 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?
// 是否启用验证密码插件。如果想设置简单的密码选N,我这里选的启用
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: 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.

// 是否移除匿名用户
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) : 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数据库
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!

这样就可以使用设置好的root密码登陆了:

$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.28 Homebrew

Copyright (c) 2000, 2019, 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>

相关文章

网友评论

      本文标题:mac通过Homebrew安装mysql

      本文链接:https://www.haomeiwen.com/subject/fmvugctx.html