macOS中安装完MySQL后如何配置

已参考下列教程
https://www.cnblogs.com/xuyatao/p/6932885.html
https://blog.csdn.net/fghsfeyhdf/article/details/78799270

服务已可以正常开启

图片说明

另外请大神看一下环境变量的配置是否正确

图片说明

数据库链接信息配置完成后进行链接,报错如下

图片说明

2059 - Authentication plugin 'caching_sha2_password' cannot be loaded: dlopen(../Frameworks/caching_sha2_password.so, 2): image not found

使用mysql -u root -p登录mysql

提示报错ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

经过查询得知为初始密码不对的访问问题,mysql的root用户不会使用安装时输入的密码?(安装时设置为a123456)

使用方案:

方案1:
更改mysql目录中的my-default.cnf文件,但是进了目录下发现没有此文件

图片说明

so~ 在[mysqld] 的配置项下添加 skip-grant-tables 方法失败
方案2:
使用sudo mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

sudo mysql -u root mysql

到这报错如下
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

[1]+ Stopped sudo mysqld_safe --user=mysql --skip-grant-tables --skip-networking

方案再次失败

求解

mysql服务未正常运行,或者socket文件路径在配置文件中设置不完整
https://www.cnblogs.com/wzg123/p/6723338.html

1、安装:sunyichaodeMacBook-Pro:~ sunyichao$ brew install mysql
2、开启mysql:mysql.server start
2、使用mysql的配置脚本:/usr/local/opt/mysql/bin/mysql_secure_installation //mysql 提供的配置向导
启动这个脚本后,即可根据如下命令提示进行初始化设置

sunyichaodeMacBook-Pro:~ sunyichao$ /usr/local/opt/mysql/bin/mysql_secure_installation //mysql 提供的配置向导
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD PLUGIN can be used to test passwordsand 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?

Press y|Y for Yes, any other key for No: k //是否采用mysql密码安全检测插件(这里作为演示选择否,密码检查插件要求密码复杂程度高,大小写字母+数字+字符等)
Please set the password for root here. // 首次使用自带配置脚本,设置root密码

New password:

Re-enter new password:

By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for 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? [Y/n] 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.

Disallow root login remotely? [Y/n] 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.

Remove test database and access to it? [Y/n] 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? [Y/n] Y//重新载入权限表
... Success!

All done! If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

Cleaning up...
sunyichaodeMacBook-Pro:~ sunyichao$

MySQL安装完之后会弹出一个窗口,里面提供了你首次登录时应该使用的密码,而不是你自己设置的那个,注意不要切屏太快,那个窗口很容易被忽视

mac上还是建议用homebrew来安装,特别好用

你这个是因为在mysql安装时候选择了版本8以上的密码加密选项,SHA2的方式对你的密码进行了加密。
而Navicat Premium并没有SHA相关插件。所以密码核对不上。
我刚遇到这个问题。
下面说说我的结论

Mysql 在8版本新加入了SHA加密方式,所以在没有相关加密插件的Navicat Premium无法解密密码并进行连接的。

所以在安装时候请选择

第二个加密方式 Use Legacy Password Encryption

如果点错了也不要紧,在系统偏好设置里面选择 mysql

图片说明

图片说明

点击Initialize Database就会弹出设置选项。

图片说明

重新设置密码,即可连接成功。