创建用户:
grant all on *.* to 'user1'@'localhost' identified by '123456a';
all:所有操作
*.*:所有数据库.所有表
mysql默认用sock登入,就是登入时只要用户密码不需要指定ip,对应的就是localhost,如果用IP127.0.0.1登入时需要-h指定ip。如果要修改,不需要删除,直接覆盖。
grant SELECT,UPDATE,INSERT on db1.* to 'user2'@'192.168.247.160' identified by '123456a';
查看mysql用户对数据库的权限:
show grants; #显示出当前用户的权限
查看指定用户:
show grants for user2@192.168.247.160; #后面要加ip
show grants for user1@'%';