# grant 权限 on 数据库对象 to 用户
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
-
myuser:用户名
-
mypassword:密码(可以与本地的不一致,但是推荐设置为一致便于维护)
-
*.*:第一个表示所有库,第二为库下所有表
-
针对某个库做授权
grant all on bank_reserve.* to 'myuser'@'%' identified by "mypassword" with grant option;
-
撤销授权:REVOKE
revoke 跟 grant 的语法差不多,只需要把关键字 “to” 换成 “from” 即可:
grant all on *.* to dba@'%';
revoke all on *.* from dba@'%';
针对表做权限
grant insert,update,select on gy3.* to user1@'%';
刷新权限
修改权限后,需要重启服务或者刷新权限
flush privileges;