Oracle数据库的登录以及常用数据导入查询

1、Oracle数据库的登录:

1、登录到数据库服务器

2、登录到SQLPlus

su - oracle
sqlplus / as sysdba

3、【可选】连接要具体操作的用户

conn 用户名/密码

2、用户的创建以及数据库文件的导入

用户的创建

1、使用oracle用户:
	su - oracle
2、登录:
	sqlplus / as sysdba
3、创建用户及设置密码:
	create user 用户名 identified by 密码;
4、给数据库用户授权:
	grant dba to 用户名;
	grant create session,resource to 用户名;
删除用户
	drop user 用户名 cascade;

数据库文件的导出(备份):

注意:

  如果公司要求使用的用户名或者密码是包含特殊符号,比如@,这时候就需要进行一些转义,比如下面密码包含@,则要使用双引号括起来:

  nohup exp userid='username/"KNfc2@#"'

参考:https://www.cnblogs.com/lhrbest/p/6560906.html


进入到oracle用户执行:
    su - oracle
后台导出:
	nohup exp userid=数据库用户名/数据库密码@主机IP:1521/服务名 file=/备份文件名.dmp > /日志文件.log 2>&1 &
	nohup exp userid=username/userpasswd@192.168.145.xx:1521/orcl file=/xxx.dmp > /xxx.log 2>&1 &
导出指定的表:
	nohup exp userid=username/userpasswd@192.168.145.xx:1521/orcl file=/xxx.dmp TABLES=表名[多个表用逗号隔开]  > /xxx.log 2>&1 &
增量导出:    
(1)“完全”增量导出(Complete)    
	即备份整个数据库,包括所有用户的数据:    
		$exp   system/manager   inctype=complete   file=990702.dmp    
(2)“增量型”增量导出    
	备份上一次备份后改变的数据。比如:    
		$exp   system/manager   inctype=incremental   file=990702.dmp    
(3)“累计型”增量导出(Cumulative)    
	累计型导出方式只是导出自上次“完全”   导出之后数据库中变化了的信息。比如:    
		$exp   system/manager   inctype=cumulative   file=990702.dmp

数据库文件的导入:

参数说明:

  full=y,是导入文件中全部内容,有可能有多个用户的内容。

  

说明:一般情况下,不需要导入某张表,是因为这张表数据量庞大,就需要使用下面参数:

  ignore=n,Oracle不执行CREATE TABLE语句,同时也不会将数据插入到表中,而是忽略该表的错误,继续恢复下一个表。

  statistics=none,是为了不导入统计信息,如果表很大,导入统计信息会花很长时间。

进入到oracle用户执行:
    su - oracle
后台导入:
	nohup imp 数据库用户名/密码@本机主机IP:端口/服务名 file=/xxx/xxx.dmp  full=y ignore=n STATISTICS=NONE > /日志文件.log 2>&1 &	
	nohup imp username/userpasswd@192.168.179.xxx:1521/orcl file=/xxx.dmp full=y ignore=n STATISTICS=NONE > /日志文件.log 2>&1 &		
导入指定的表:
	nohup imp username/userpasswd@192.168.179.xxx:1521/orcl file=/xxx.dmp TABLES=表名[多个表用逗号隔开] full=y ignore=y STATISTICS=NONE > /日志文件.log 2>&1 &

3、数据查询

1、查看并发连接数

select machine,count(*) from gv$session group by machine;

2、查看日志表空间的大小以及使用:

SELECT a.tablespace_name "表空间名",
a.bytes / 1024 / 1024 "表空间大小(M)",
(a.bytes - b.bytes) / 1024 / 1024 "已使用空间(M)",
b.bytes / 1024 / 1024 "空闲空间(M)",
round(((a.bytes - b.bytes) / a.bytes) * 100, 2) "使用比"
FROM (SELECT tablespace_name, sum(bytes) bytes
FROM dba_data_files
GROUP BY tablespace_name) a,
(SELECT tablespace_name, sum(bytes) bytes, max(bytes) largest
FROM dba_free_space
GROUP BY tablespace_name) b
WHERE a.tablespace_name = b.tablespace_name
ORDER BY ((a.bytes - b.bytes) / a.bytes) DESC

3、查看日志表空间目录:

select tablespace_name,
file_id,
file_name,
round(bytes / (1024 * 1024), 0) total_space
from sys.dba_data_files
order by tablespace_name

 4、查看日志表空间是否为自动扩展

SELECT file_id, file_name, tablespace_name, autoextensible, increment_by
FROM dba_data_files
WHERE tablespace_name = 'USERS' 
or tablespace_name = 'SYSAUX' or tablespace_name = 'UNDOTBS1';
ORDER BY file_id desc;

5、扩容表空间大小  

alter tablespace 用户名 add datafile '表空间全路径' size 30720m;

 6、设置表空间自动扩展

alter database datafile '表空间全路径' autoextend on;

  

 

原文地址:https://www.cnblogs.com/zhangzhixi/p/15234344.html