1、cmd 登陆mysql
mysql -uroot -p123456
2、设置访问权限
grant all privileges on *.* to ‘root‘@‘%‘ identified by ‘123456‘ with grant optio
如果出现grant all privileges on *.* to ‘root‘@‘%‘ identified by ‘123456‘ with grant optio报错
原因: mysql的版本问题,这条语句适用于MySQL8.0之前
解决: mysql8.0及以上版本需要使用以下语句:
create user root@'%' identified by '123456';
grant all privileges on *.* to root@'%' with grant option;
3、刷新权限
flush privileges;
4、然后虚拟机连接本机mysql测试