1.进行授权

    1. //grant就是用来做授权的 all是所有权限(增删改查) *.*是 代表所有库 to "user"是用户(@是所有用户常用) identified by'passwd'是认证密码方式登录
    2. mysql> grant all on *.* to 'user1' identified by'passwd';
    3. Query OK, 0 rows affected (0.00 sec)
    4. //加上@是指定IP 在登陆时也要使用IP登录 -h.....
    5. mysql> grant SELECT,UPDATE,INSERT on db1.* to 'user2'@'192.168.133.1' identified by 'passswd';
    6. Query OK, 0 rows affected (0.00 sec)
    7. mysql> grant all on db1 .*to'user3'@'%'identified by'passwd';
    8. Query OK, 0 rows affected (0.01 sec)

    查看授权表

    1. mysql> show grants;
    2. +----------------------------------------------------------------------------------------------------------------------------------------+
    3. | Grants for root@localhost |
    4. +----------------------------------------------------------------------------------------------------------------------------------------+
    5. | GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*659B2EB27EB8DC40B334458DC50B62CD56DD9441' WITH GRANT OPTION |
    6. | GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION |
    7. +----------------------------------------------------------------------------------------------------------------------------------------+
    8. 2 rows in set (0.00 sec)
    9. mysql> show grants for user2@192.168.133.1;
    10. +------------------------------------------------------------------------------------------------------------------+
    11. | Grants for user2@192.168.133.1 |
    12. +------------------------------------------------------------------------------------------------------------------+
    13. | GRANT USAGE ON *.* TO 'user2'@'192.168.133.1' IDENTIFIED BY PASSWORD '*59C70DA2F3E3A5BDF46B68F5C8B8F25762BCCEF0' |
    14. | GRANT SELECT, INSERT, UPDATE ON `db1`.* TO 'user2'@'192.168.133.1' |
    15. +------------------------------------------------------------------------------------------------------------------+
    16. 2 rows in set (0.00 sec)