homebrew 安装mysql_使用Homebrew安装MySQL

安装命令:

brew install mysql

安装完成之后,启动mysql:

mysql.server start

发现无此命令:

command not found

首先,检查是否是安装了。重新执行一遍:

brew install mysql

提示:

Warning: mysql-5.7.17 already installed, it's just not linked

然后网上查找解决方法,执行:

brew link --overwrite mysql

报错:

Linking /usr/local/Cellar/mysql/5.7.17...

Error: Could not symlink share/man/man8/mysqld.8 /usr/local/share/man/man8 is not writable.

查找解决方法,以下语句执行成功:

sudo chown -R 'username' /usr/local

解决了问题后,重新执行:

brew link --overwrite mysql

提示:

Linking /usr/local/Cellar/mysql/5.7.17... 93 symlinks created

重新执行:

mysql.server start

没有错误。表示这时我们已经启动mysql服务器,按照brew的提示设置管理员密码。

mysql_secure_installation

然后根据提示操作就好了,以下代码来自文献[1]。

1 Securing the MySQL server deployment.2

3 Connecting to MySQL using a blank password.4

5 VALIDATE PASSWORD PLUGIN can be used to test passwords6 and improve security. It checks the strength of password7 and allows the users to set only those passwords whichare8 secure enough. Would you like to setup VALIDATE PASSWORD plugin?

9

10 Press y|Y for Yes, any other key forNo: y11

12 There are three levels of password validation policy:13

14 LOW Length >= 8

15 MEDIUM Length >= 8, numeric, mixed case, and special characters16 STRONG Length >= 8, numeric, mixed case, special characters and dictionary file

17 //这里提示选一个密码强度等级

18 Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1

19 Please set the password forroot here.20 //然后按照所选的密码强度要求设定密码

21 New password:22

23 Re-enter new password:24

25 Estimated strength of the password: 50

26 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key forNo) : y27 ... Failed!Error: Your password does not satisfy the current policy requirements28

29 New password:30

31 Re-enter new password:32

33 Estimated strength of the password: 100

34 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key forNo) : y35 By default, a MySQL installation has an anonymous user,36 allowing anyone to log into MySQL without having to have37 a user account created for them. This is intended only for

38 testing, and to makethe installation go a bit smoother.39 You should remove them before moving into a production40 environment.41 //这里删除默认无密码用户

42 Remove anonymous users? (Press y|Y for Yes, any other key forNo) : y43 Success.44

45

46 Normally, root should only be allowed to connect from47 'localhost'. This ensures that someone cannot guess at48 the root password from the network.49 //禁止远程root登录,我选的是不禁止。因为我的mac上的数据库不会放到公网上,也不会存什么敏感数据

50 Disallow root login remotely? (Press y|Y for Yes, any other key forNo) : no51

52 ... skipping.53 By default, MySQL comes with a database named 'test'that54 anyone can access. This is also intended only fortesting,55 and should be removed before moving into a production56 environment.57

58 //这里删除默认自带的test数据库

59 Remove test database and access to it? (Press y|Y for Yes, any other key forNo) : y60 -Dropping test database...61 Success.62

63 -Removing privileges on test database...64 Success.65

66 Reloading the privilege tables will ensure that all changes67 made so far will take effect immediately.68

69 Reload privilege tables now? (Press y|Y for Yes, any other key forNo) : y70 Success.71

72 All done!

执行:

mysql -r root -p

输入密码,成功进入:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 8

Server version: 5.7.17 Homebrew

测试一下:

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| sys                |

+--------------------+

4 rows in set (0.03 sec)

全部👌 !

参考文献:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值