MySQL数据库赋予用户权限
2021-03-21 本文已影响0人
乂尤先生
MySQL清空数据库的操作:
truncate table tablename;
远程登录MySQL:
mysql -h ip -u root -p 密码
创建用户:
格式:
grant 权限 on 数据库.* to 用户名@登录主机 identified by "密码"
例1:增加一个test1
用户,密码为123456
,可以在任何主机上登录,并对所有数据库有查询,增加,修改,删除的功能。需要在mysql的root
用户下进行
grant select,insert,update,delete on *.* to test1@"%" identified by "123456"
例2:增加一个test2
用户,密码为123456
,只能在本地登录,并对数据库有查询,增加,修改和删除的功能,需要在MySQL的root
用户下进行
grant select,insert,update,delete on *.* to test2@"192.168.1.%" identified by "123456"
例3: 授权用户test3
拥有数据库testdb的所有权限
grant all privileges on testdb.* to test3@localhost identified by "123456"
授权用户创建表,索引,视图,存储过程,函数等权限
授权test1
用户创建,修改,删除数据表结构权限
grant create on *.* to test1@'%' ;
grant alter on *.* to test1@'%';
grant drop on *.* to test1@'%';
授权test1
用户操作MySQL外键权限
grant references on *.* to test1@'%';
授权test1
用户操作MySQL临时表权限
grant create temporary tables on *.* to test1@'%';
授权test1
用户操作MySQL索引权限
grant index on *.* to test1@'%';
授权test1
用户操作MySQL视图,查看视图源代码权限
grant create view on *.* to test1@'%';
grant show view on *.* to test1@'%';
授权test1
用户操作MySQL存储过程,函数权限
grant create routine on *.* to test1@'%';
grant alter routine on *.* to test1@'%';
grant execute on *.* to test1@'%';
查看用户权限:
查看当前用户权限
show grants;
查看其它用户权限
show grants for test1@localhost;
修改用户密码:
update mysql.user set password=password('123456') where User='test1' and Host='localhost'
删除用户:
delete from user where user='test2' and host='localhost'
删除账户及权限
drop user 用户名@'%'
drop user 用户名@localhost