[client]

default-character-set=utf8

[mysql]

default-character-set=utf8

[mysqld]

collation-server = utf8_unicode_ci

init-connect='SET NAMES utf8'

character-set-server = utf8

第二种情况,那是因为用户身份认证的加密方式不兼容导致的,mysql8.0中默认方式为caching_sha2_password,引起老版本兼容性问题,老版本加密方式为mysql_native_password。

新建用老版加密方式初始化密码的用户即可:

CREATEUSERusername@localhostidentifiedwithmysql_native_passwordby'password';

然后在my.cnf中添加一行:default_authentication_plugin=mysql_native_password;