Mysql 8.0
#创建用户 db_user 换成root表示root用户
MySQL [(none)]> create user db_user@'%' identified by 'db_pass';
#授权 db_name 用*替代表示访问所有数据库
MySQL [(none)]> grant all privileges on db_name.* to db_user@'%' with grant option;
#退出数据库控制台,特别注意有分号
MySQL [(none)]> exit;
Mysql 8.0以下
MySQL [(none)]> grant all privileges on db_name.* to db_user@'%' identified by 'db_pass';
#授权语句,特别注意有分号
MySQL [(none)]> flush privileges;
#退出数据库控制台,特别注意有分号
MySQL [(none)]> exit;
创建用户
create user 'username'@'%' identified by 'password';
username 用户名 %所有ip password 密码
授权所有数据库
grant all privileges on *.* to 'username'@'%';
flush privileges;