美文网首页
数据库常用语句总结

数据库常用语句总结

作者: 奇哥威武 | 来源:发表于2023-07-26 10:48 被阅读0次

postgresql

创建用户

create user 用户名 with password '密码';

赋予用户登陆权限

alter user 用户名 login;

赋予用户数据库链接权限

GRANT Connect ON DATABASE "数据库名" TO "用户名";

赋予用户当前数据库下所有schema链接权限

SELECT distinct 'GRANT Usage ON SCHEMA '|| table_schema ||' to 用户名 ;' from information_schema.tables

查找当前postgresql下所有的schema ,并赋予所有schema下的表所有权限到指定账户

SELECT distinct 'GRANT ALL PRIVILEGES on ALL TABLES IN SCHEMA '|| table_schema ||' to 用户名;' from information_schema.tables

查询数据库链接情况

SELECT now()-query_start,current_query,*FROM pg_stat_activity
WHERE
current_query != '<IDLE>' ORDER BY now()-query_start desc

清掉链接

select pg_terminate_backend(57050)

mysql

创建用户并可以远程登陆

create user '用户名'@'%' indentified by '密码'

赋权指定库下所有的表所有权限

grant all privileges on 数据库名.* to '用户名'@'%'

刷新权限生效

flush privileges;

相关文章

网友评论

      本文标题:数据库常用语句总结

      本文链接:https://www.haomeiwen.com/subject/bxkkpdtx.html