MySQL 5.7版本使用如下(可能5的版本都适用)
# 1. 登录
mysql -uroot -pmysql
# 2. 授权root用户对所有数据库在任何ip都可以进行操作
grant all on *.* to root@"%" identified by "mysql" with grant option;
# 3. 刷新数据库
flush privileges;
MySQL 8版本因为不支持上面语法,所以设置远程登录不一样
# 以下操作为用户名root 密码 mysql作为示例,具体可以根据自己的数据库设置而定
# 1. 登录
mysql -u root -pmysql
# 2. 第二步
create user 'root'@'%' identified by 'mysql';
# 3. 修改密码为永不过期
alter user 'root'@'%' identified by 'mysql' password expire never;
# 4. 修改密码并指定MySQL用户登录密码加密规则为mysql_native_password
alter user 'root'@'%' identified with mysql_native_password by 'mysql';
# 5. 授权
grant all on *.* to 'root'@'%';
# 6. 刷新
flush privileges;