安装命令:
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 passwords
6 and improve security. It checks the strength of password
7 and allows the users to set only those passwords which are
8 secure enough. Would you like to setup VALIDATE PASSWORD plugin?
9
10 Press y|Y for Yes, any other key for No: y
11
12 There are three levels of password validation policy:
13
14 LOW Length >= 8
15 MEDIUM Length >= 8, numeric, mixed case, and special characters
16 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 for root 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 for No) : y
27 ... Failed! Error: Your password does not satisfy the current policy requirements
28
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 for No) : y
35 By default, a MySQL installation has an anonymous user,
36 allowing anyone to log into MySQL without having to have
37 a user account created for them. This is intended only for
38 testing, and to make the installation go a bit smoother.
39 You should remove them before moving into a production
40 environment.
41 // 这里删除默认无密码用户
42 Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
43 Success.
44
45
46 Normally, root should only be allowed to connect from
47 'localhost'. This ensures that someone cannot guess at
48 the root password from the network.
49 // 禁止远程root登录,我选的是不禁止。因为我的mac上的数据库不会放到公网上,也不会存什么敏感数据
50 Disallow root login remotely? (Press y|Y for Yes, any other key for No) : no
51
52 ... skipping.
53 By default, MySQL comes with a database named 'test' that
54 anyone can access. This is also intended only for testing,
55 and should be removed before moving into a production
56 environment.
57
58 // 这里删除默认自带的test数据库
59 Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
60 - Dropping test database...
61 Success.
62
63 - Removing privileges on test database...
64 Success.
65
66 Reloading the privilege tables will ensure that all changes
67 made so far will take effect immediately.
68
69 Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
70 Success.
71
72 All done!
执行:
mysql -u 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)
最后开通下navicate登录权限:
ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘password’;
FLUSH PRIVILEGES;