MySQL添加新用户、为新用户分配权限

1、使用root用户登录mysql

2、添加具有本地(localhost/127.0.0.1)访问权限的用户

    #create user 'newuser'@'localhost' identified by 'password';

3、创建具有远程访问权限的用户 

    #create user 'newuser'@'%' identified by 'password';

    创建之后记得执行下面指令更新权限:

    #flush privileges; 

3、为新用户分配本地权限,可以指定数据库dbname和表名,可以用*替指所有。

    #grant all privileges on `dbname`.* to 'newuser'@'localhost' identified by 'password';  

4、为新用户分配远程权限,可以指定数据库dbname和表名,可以用*替指所有。

    #grant all privileges on `dbname`.* to 'newuser'@'%' identified by 'password';  

    分配好之后之后记得执行下面指令更新权限:

    #flush privileges; 

5、如果还有问题,可以使用root账号登陆上去查询一下,再看看有没问题。

    #use mysql

    #select Host, User, Password from user;

    可以大致发现发现问题,如下图:

    




猜你喜欢

转载自blog.csdn.net/ycg514230/article/details/80197277