创建用户
//允许本地ip访问数据库的用户 create user 'test1'@'localhost' identified by '123'; //所有的ip都可以访问数据库的用户 create user 'test2'@'%' identified by '123';
刷新授权
flush privileges;
新建用户并赋予数据库所有权限(其中%代表登录用户的ip不限 localhost只能本地)
//授予指定数据库的所有权限 grant all privileges on `test_db`.* to 'test3'@'%' identified by '123' with grant option; //授予指定数据库部分权限 grant select,update on demoDB.* to demo@'%' identified by '1234'; //授予所有数据库部分权限 grant select,delete,update,create,drop on *.* to demo@"%" identified by "1234"; //授予所有数据库所有权限 grant all privileges on *.* to demo@"%" identified by "1234";
修改指定用户的密码
mysql>update mysql.user set password=password('新密码') where User="demo" and Host="localhost"; mysql>flush privileges;
删除用户
mysql>Delete FROM user Where User='demo' and Host='localhost'; mysql>flush privileges; mysql>drop database demoDB; //删除用户的数据库 删除账户及权限:>drop user 用户名@'%'; >drop user 用户名@ localhost;