授权远程登录
我们数据库需要再远程登录维护时,需要授权。
1、查看授权情况:select host,user,authentication_string from user;
注:在mysql 5.7.9以后废弃了password字段和password()函数
2.添加root账号一条DBA的权限:grant all privileges on *.* to root@'%' identified by "密码";
3.立即生效:flush privileges;
4.到此结束。
当然第二步中您也可以使用该语句修改ROOT权限:update user set host = '%' where user = 'root';
权限分配命令说明
权限语法:grant [operate] on db.table to user@'ip';
查看权限:show grants 用户名;
a) operate:操作,即权限范围(select、update、delete、insert、view、drop、alter等)
当operate为为存储过程或函数时,需要用:
grant execute on procedure db.table to user@'ip';
grant execute on function db.table to user@'ip';
b)db:数据库名称;
c)table:表名称
d)user:用户名;
e)ip:哪些ip可以访问,如 %(所有ip)、localhost、127.0.0.1等
常用的权限分配如下:
1.管理某个数据库的权限:grant all privileges on 数据库名 to 用户名@’%’
2.管理所有数据库的权限:grant all on *.* to 用户名@’%’
3.只可以查看的权限:grant select on *.* to 用户名@’%’;
4.只可以查看订单表(order)的权限:grant select on 数据库名.order to 用户名@’%’;