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所有,转载请注明来源,谢谢合作。