1.进行授权
//grant就是用来做授权的 all是所有权限(增删改查) *.*是 代表所有库 to "user"是用户(@是所有用户常用) identified by'passwd'是认证密码方式登录
mysql> grant all on *.* to 'user1' identified by'passwd';
Query OK, 0 rows affected (0.00 sec)
//加上@是指定IP 在登陆时也要使用IP登录 -h.....
mysql> grant SELECT,UPDATE,INSERT on db1.* to 'user2'@'192.168.133.1' identified by 'passswd';
Query OK, 0 rows affected (0.00 sec)
mysql> grant all on db1 .*to'user3'@'%'identified by'passwd';
Query OK, 0 rows affected (0.01 sec)
查看授权表
mysql> show grants;
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*659B2EB27EB8DC40B334458DC50B62CD56DD9441' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
mysql> show grants for user2@192.168.133.1;
+------------------------------------------------------------------------------------------------------------------+
| Grants for user2@192.168.133.1 |
+------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'user2'@'192.168.133.1' IDENTIFIED BY PASSWORD '*59C70DA2F3E3A5BDF46B68F5C8B8F25762BCCEF0' |
| GRANT SELECT, INSERT, UPDATE ON `db1`.* TO 'user2'@'192.168.133.1' |
+------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)