mysql 添加用户并分配权限

1.登录mysql
    mysql -u root -p
2.跳转到mysql库
    use mysql
3.创建本地访问的用户
    create user sjh@localhost identified by '123456';
    注:当出现Your password does not satisfy the current policy requirements错误时,需要调整其密码复杂度
        a.修改密码策略
            set global validate_password_policy=0;
        b.修改密码长度
            set global validate_password_length=1;
4.创建外网访问的用户
    create user 'sjh'@'%' identified by '123456';
5.授予用户在本地服务器对该数据库的全部权限
    grant all privileges on dbname.* to sjh@localhost identified by '123456';
6.授予用户通过外网IP对于该数据库的全部权限
    grant all privileges on dbname.* to 'sjh'@'%' identified by '123456';
7.刷新权限
    flush privileges;

Logo

更多推荐