mysql 的用户权限

  1. 查看MySQL的用户权限

    show grants for "username"@'host';

  1. 添加新用户

    允许本地IP访问localhost:127.0.0.1

    use mysql;

    create user 'test'@'localhost' identified by '123456';

    允许外网IP访问

    create user 'test'@'%' identified by '123456';

    '%'表示对所有非本地主机的授权,不包括localhost

     

    刷新授权

    flush privileges;

  2. 给用户分配权限

    授予用户通过外网ip对于该数据库的全部权限

    grant all privileges on testdb.* to 'test'@'%' identified by '123456';

    授予用户在本地服务器对该数据库的全部权限

    grant all privileges on testdb.* to 'test'@'localhost' identified by '123456';

    授予用户通过外网IP对全部数据库的所有权限

    grant all privileges on *.* to 'test'@'%' identified by '123456';
  3. 删除用户

    delete from mysql.user where user='test' and host ='localhost';

    drop user 用户名@'%';

    drop user 用户名@localhost;

  4. 修改密码

    update mysql.user set password=password('新密码') where User="test" and Host="localhost";

   参考了:https://blog.csdn.net/piaocoder/article/details/53704126

posted @ 2018-07-30 10:00  烟雨蒙尘  阅读(151)  评论(0)    收藏  举报