赞
踩
登录mysql
mysql -u root -p
切换mysql数据库
use mysql;
查询当前允许登录IP及用户
select Host, User from user;
--Host 字段为%或空表示所有 IP 都可登录
5.x: 版本如果用户不存在会创建用户。
grant all on *.* to 'username'@'ip' identified by 'password' with grant option;
8.x: 版本需要先创建的用户后再授权。
create user 'username'@'ip' identified with mysql_native_password by 'password';
grant all privileges on *.* to 'username'@'ip';
grant all
表示授权所有操作,*.*
表示授权所有数据库的所有表。
也可以赋予部分操作权限:
grant select,create,drop,update,alter on *.* to 'username'@'ip' identified by 'password' with grant option;
删除用户的权限
DELETE FROM user WHERE User='username' and Host='ip';
最后更新配置刷新权限
FLUSH PRIVILEGES;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。