mysql表空间的创建、扩充、查看

1步:创建临时表空间
create temporary tablespace user_IQDA_temp  
tempfile '/u01/app/oracle/oradata/orcl/user_IQDA_temp.dbf'
size 500m  
autoextend on  
next 50m maxsize 2048m  
extent management local;2步:创建数据表空间
create tablespace user_IQDA  
logging  
datafile '/u01/app/oracle/oradata/orcl/user_IQDA.dbf'
size 5000m  
autoextend on  
next 50m maxsize 10240m  
extent management local;3步:创建用户并指定表空间
create user IQDA identified by password  
default tablespace user_IQDA  
temporary tablespace user_IQDA_temp;4步:给用户授予权限
grant connect,resource,dba to IQDA;5步:修改密码
alter user IQDA identified by IQDA;

//删除用户 只删除schma_object 不删除用户所在的表空间
drop user gsts_cqgd cascade;
//删除空的表空间,但是不包含物理文件
drop tablespace tablespace_name;
//删除非空表空间,但是不包含物理文件
drop tablespace tablespace_name including contents;
//删除空表空间,包含物理文件
drop tablespace tablespace_name including datafiles;
//删除非空表空间,包含物理文件
drop tablespace tablespace_name including contents and datafiles;
//如果其他表空间中的表有外键等约束关联到了本表空间中的表的字段,就要加上CASCADE CONSTRAINTS 
drop tablespace tablespace_name including contents and datafiles CASCADE CONSTRAINTS;


扩充表空间:
//查看表空间是否自动扩展
select file_id,file_name,tablespace_name,autoextensible,increment_by from dba_data_files
where tablespace_name='USER_IQDA' order by file_id desc; 
//查询数据文件位置
select * from dba_data_files t where t.tablespace_name='USER_IQDA'; 
//增加数据文件 
alter tablespace TBS_IQDA add datafile '/oracle/oradata/shyegdb/TBS_IQDA_3.dbf' size 10240M;

修改表空间名称:
alter tablespace  TEST rename to TEST1;
更改表空间大小:alter database datafile '/oracle/oradata/bigdata/user_IQDA.dbf' resize 30720M;
ALTER DATABASE DATAFILE '/oracle/oradata/bigdata/user_IQDA.dbf' AUTOEXTEND ON NEXT 50M MAXSIZE 51200M;

如果是linux系统,文件大小最大为32G,UNIX系统为64G,单个文件无法设为50G,此时可以增加数据文件。
增加数据文件:
ALTER TABLESPACE "USER_IQDA" ADD  DATAFILE  '/oracle/oradata/bigdata/user_IQDA1.dbf' SIZE 5G AUTOEXTEND ON NEXT 50m MAXSIZE 30720M;


查看表空间大小及使用率:
select b.file_name 物理文件名,b.tablespace_name 表空间,b.bytes / 1024 / 1024 大小M,(b.bytes - sum(nvl(a.bytes, 0))) / 1024 / 1024 已使用M,
substr((b.bytes - sum(nvl(a.bytes, 0))) / (b.bytes) * 100, 1, 5) 利用率   
from dba_free_space a,dba_data_files b   
where a.file_id = b.file_id
group by b.tablespace_name,b.file_name, b.bytes   
order by b.tablespace_name;

或查看当前用户表空间及剩余空间:
select
 a.bytes/1024/1024 "used(MB)",
b.bytes/1024/1024 "free(MB)",
a.bytes/1024/1024+b.bytes/1024/1024 "total(MB)"
 from user_ts_quotas a,user_free_space b 
where a.TABLESPACE_NAME=b.TABLESPACE_NAME and a.TABLESPACE_NAME='SSPATBS';

博客主页:https://blog.csdn.net/yisumi

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值