mysql新建用户并授权

创建用户

create user '#user'@'%' identified by "#password";  其中,%的位置表示是否允许远程访问,若是localhost,则不允许远程访问。

修改账号的密码

alter user '#user'@'%' identified by '#newpassword';

授权全部权限给指定用户

grant all privileges on #database.#table to #user;

撤销用户在指定数据库上的全部权限

revoke all privileges on #database.#table from #user;

查看用户权限

show grants for #user;

删除用户

drop user #user;

刷新,每次更新授权之后要实时刷新

flush privileges;

新建一个数据库后,非root账户可以看到information_schema与performance_schema两个数据库,这两个是自带的,前一个是视图,不是真正的数据库表,第二个普通用户没有访问权限。不用管它们,只管创建自己需要的数据库就行。

posted @ 2023-03-15 20:20  江湖凶险  阅读(264)  评论(0编辑  收藏  举报