Mac 安装 mysql8 版本会遇到不少的坑, 大家可以用如下方式解决:
1, 用 brew 安装最新版本的 MySQL, 我安装的时候还是 8.1.2
brew install MySQL
2, 开启 MySQL 服务
brew services start MySQL
3, 安装安全插件, 即为 MySQL 的 root 帐号生成密码
- mysql_secure_installation
- 3.1
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?
- Press y|Y for Yes, any other key for No:
此时选 y, 开启密码组件
- 3.2
- 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
3.3
Please set the password for root here.
- New password:
- Re-enter new password:
这一步是输入密码和确认密码
- 3.4
- Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) :
输入 y, 确认提交密码
- 3.5
- 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, 删除匿名用户
- 3.6
- Normally, root should only be allowed to connect from
- 'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) :
如果要禁止 root 远程登录, 可以选 yes, 否则选 no. 本地的话, 我建议选 no 吧.
- 3.7
- 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, 删除 test 数据库, 我们自己建其他库就是了
- 3.8
- 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 就是了
好了, 以上操作完之后, 就为 root 创建了一个密码了.
4, 此时你兴致勃勃的去 Sequal pro 登录 (或其他客户端), 此时会提示
Authentication plugin 'caching_sha2_password' cannot be loaded: dlopen(/usr/local/MySQL/lib/plugin/caching_sha2_password.so, 2): image not found
说明客户端不支持这种加密方式, 因为默认生成的 root 的密码是用 caching_sha2_password 插件加密的. 而客户端找不到 caching_sha2_password 插件, 于是登录不上.
4.1 我们先通过终端输入: MySQL -u root -p 登录 MySQL, 然后 MySQL>use MySQL
4.2 CREATE USER 'test'@'%' IDENTIFIED WITH mysql_native_password BY '12345678'(按照配置的安全等级来, 我配置的 0, 所以只要满足 8 位以上就可以了);
4.3 grant all on . to test@'%'; 需要给 test 帐号授权, 否则 test 帐号没任何权限.
好了, 以上操作完之后, 客户端就可以登录 MySQL 了.
如在安装过程中遇到问题, 请联系我 (qq:378439929)
本文版权归逍遥 jc 所有, 转载请注明来源, 谢谢合作.
来源: http://www.jianshu.com/p/428174574190