1.登录
mysql -uroot -p
use mysql;
// 查看用户列表及权限 host为本地访问
select user,host,plugin from user;
//给 root开启远程访问权限
GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY '123456';
//刷新权限 可以用远程连接
FLUSH PRIVILEGES;
2.新建用户并给某个库的权限
//1.创建用户 @'%可以远程访问'
create user 'test'@'%' identified by '123456';
//2.给用户test库的权限
grant all privileges on `test`.* to 'test'@'%';
第二步 可能报错 Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
可能是 由于root用户没有SYSTEM_USER权限 再执行步骤2
//给root 管理员权限
grant system_user on *.* to 'root';
最后刷新权限
FLUSH PRIVILEGES;