最近新装了Mysql5.7,按如下设置好了允许远程连接
(1)找到mysql配置文件并修改
sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf 将bind-address=127.0.0.1注释
(2)登录mysql,运行命令
grant all privileges on *.* to 'root'@'%' identified by 'mysql' with grant option; # 所有的地址都可以使用root用户,密码为mysql远程访问所有的数据库 flush privileges;
(3)检查了下防火墙并没有屏蔽端口号
(4)直接在navicate上连接mysql数据库,报错如下:

查了很多博客,未果,后面仔细分析应该是密码的错误,因为自己用navicate连接数据库使用的是user为root,host为localhost的密码登陆的,如下可发现
host为localhost、%(任意ip,我们连接时使用的就是这个)的密码不一样(ps Mysql5.7版本以后password变为authentication_string)

(5)修改user为root,host为‘%’的密码,改成跟host为localhost密码一样,这样不容易忘记(若知道密码时什么就不需要改)

查看密码发现变成一样了,如下图
(6)在navicate登录,--->成功