mysql添加用户并设置数据库权限
发布日期:2021-05-14 13:23:26 浏览次数:12 分类:精选文章

本文共 867 字,大约阅读时间需要 2 分钟。

创建用户

//允许本地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;

 

上一篇:Linux系统使用定时脚本备份mysql
下一篇:小程序图片水平垂直居中显示在view中

发表评论

最新留言

网站不错 人气很旺了 加油
[***.192.178.218]2025年04月06日 13时48分54秒