数据库权限访问和远程访问

创建新用户

1.create user ‘test1’@‘localhost’ identified by ‘123456’;
grant all PRIVILEGES on . to ‘test1’@‘localhost’;赋予用户权限
FLUSH PRIVILEGES;刷新下就可以

就可以使用mysql -u test1 -p进行访问了

创建远程用户

在电脑A上操作,先为电脑B的ip创建用户, 赋予电脑B的ip访问权限,
1.create user ‘test2’@’(B的ip)’ identified by ‘123456’;
grant all PRIVILEGES on . to ‘test1’@’(B的ip)’;赋予用户权限
FLUSH PRIVILEGES;刷新下就可以

2.关闭A自身防火墙
3.在电脑B上访问A的数据库,使用mysql -h (A的ip地址) -u test2 -p
输入test2的密码就可以用电脑B作为用户test2对A电脑的数据进行操作。
ps: 可以将host设置为%,()就相当于对所有ip开放本机的数据库,
create user ‘test3’@’%’ identified by ‘123456’;
这样所有ip都可以作为test3访问本机的数据库.

删除用户

mysql>delete from user where user=’test2′ and host=‘localhost’;
mysql>flush privileges;

赋予用户权限

grant 权限 on 数据库对象 to 用户
一、grant 普通数据用户,查询、插入、更新、删除 数据库中所有表数据的权利。
grant select on testdb.* to common_user@’%’
grant insert on testdb.* to common_user@’%’
grant update on testdb.* to common_user@’%’
grant delete on testdb.* to common_user@’%’
或者,用一条 MySQL 命令来替代:
grant select, insert, update, delete on testdb.* to common_user@’%’

其他详细权限内容参照下博客

如有其他详细的需求参此博客:
https://blog.csdn.net/xuxile/article/details/53161908

猜你喜欢

转载自blog.csdn.net/weixin_43722571/article/details/98976785