本教程使用MySQL8.0+
1.MySQL连接配置
1.1Windows使用cmd查看是否连通虚拟机
ping 虚拟机IP
1.2.登录MySQL
启动:systemctl start mysqld
登录:mysql -h ip地址 -uroot -p
1.3.进入mysql
use mysql;
1.4.创建新用户(user001)再授权访问,(root用户见后面)
create user 'user001'@'%';
grant all privileges on *.* to '用户名'@'%';
1.5.更改加密方式
update user set plugin='mysql_native_password' where user ='user001';
1.6.修改密码
alter user 'user001'@'%' identified with mysql_native_password by '0000';
1.7.刷新
flush privileges;
1.8.MySQL root用户外部登录
1.9.更改加密方式
update user set plugin='mysql_native_password' where user ='user001';
1.10.更改主机名使所有主机可用root用户访问
update user set host=’%’ where user=‘root’;
1.11.查看
select host, user,plugin from user;
select host, user,plugin from user;
2.关闭防火墙
2.1.查看防火墙状态(active防火墙处于激活状态)
systemctl status firewalld.service
2.2.禁止自启动
systemctl disable firewalld.service
2.3.外部可连接测试
3.注(可略):
# grant all privileges on *.* to '用户名'@'%' identified by '密码';
# mysql8.0 以前的版本可以使用grant在授权的时候隐式的创建用户,8.0以后已经不支持,所以必须先创建用户,
然后再授权