添加用户
- 登录root用户添加本地用户
create user ‘用户名’ @‘localhost’ identified by ‘password’
- 添加远程登录用户或指定ip登录用户
create user ‘用户名’ @ ‘指定ip’ identified by ‘password’
允许在所有的地址登录把指定ip设为’%'即可
添加本地用户holt之后在本地登录不上 需要在本地创一个同名的用户即可,远程登录密码和本地登录密码可以设为不同。
运行
select user ,host from mysql.user;
查看用户:
为用户添加权限
grant all privileges on 数据库名.* to ‘用户名’@‘ip地址’ ;
如给holt远程用户添加mydb1数据库的所有权限;
grant all privileges on mydb1.* to ‘holt’@’%’ ;
添加mydb1数据库的部分权限:
grant select,insert,update,delete,create,drop on mydb1.table1 to ‘holt’@ ‘%’
添加mydb1数据库的部分表的部分权限:
grant select,insert,update,delete,create,drop on mydb1.table1 to ‘holt’@’%’
执行过后记得更新一下权限:
flush privileges;
删除用户:
Delete FROM mysql.user Where User=‘holt’ and Host=‘localhost’;
flush privileges;
或者
drop user 用户名@’%’; //删除远程用户
drop user 用户名@ localhost; //删除本地用户
给root添加远程权限
GRANT ALL PRIVILEGES ON . TO root@"%" IDENTIFIED BY “password”;