Oracle数据库入门基础知识
1、安装完成Oracle数据库后,使用sqlplus客户端登录数据库管理系统,只输入用户名,没有输入密码时,会提示口令为空,登录被拒绝。
请输入用户名:system 输入口令: ERROR:ORA-01005:给出空口令:登录被拒绝 |
2、在没有登录到Oracle数据库系统中时,使用该命令(sys/nolog)登录,会提示如下错误。
请输入用户名: sys/nolog ERROR: ORA-01017: invalid username/password; logon denied //无效的用户名/密码,登录被拒绝 |
3、使用正确的用户名密码登录Oracle数据库系统(用户名/密码@SID)
请输入用户名: system/1@orcl 连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> |
4、登录数据库系统后,可以查看当前登录的用户账户
SQL>show user; USER 为 "SYSTEM" //显示当前登录的用户 |
5、查看Oracle数据库所以用户的状态
SQL> select username,account_status from dba_users; USERNAME ACCOUNT_STATUS ------------------------------ -------------------------------- SYS OPEN SYSTEM OPEN DBSNMP OPEN SYSMAN OPEN MGMT_VIEW LOCKED OUTLN EXPIRED & LOCKED FLOWS_FILES EXPIRED & LOCKED MDSYS EXPIRED & LOCKED ORDSYS EXPIRED & LOCKED EXFSYS EXPIRED & LOCKED WMSYS EXPIRED & LOCKED USERNAME ACCOUNT_STATUS ------------------------------ -------------------------------- APPQOSSYS EXPIRED & LOCKED APEX_030200 EXPIRED & LOCKED OWBSYS_AUDIT EXPIRED & LOCKED ORDDATA EXPIRED & LOCKED CTXSYS EXPIRED & LOCKED ANONYMOUS EXPIRED & LOCKED XDB EXPIRED & LOCKED ORDPLUGINS EXPIRED & LOCKED OWBSYS EXPIRED & LOCKED SI_INFORMTN_SCHEMA EXPIRED & LOCKED OLAPSYS EXPIRED & LOCKED USERNAME ACCOUNT_STATUS ------------------------------ -------------------------------- SCOTT EXPIRED & LOCKED ORACLE_OCM EXPIRED & LOCKED XS$NULL EXPIRED & LOCKED MDDATA EXPIRED & LOCKED DIP EXPIRED & LOCKED APEX_PUBLIC_USER EXPIRED & LOCKED SPATIAL_CSW_ADMIN_USR EXPIRED & LOCKED SPATIAL_WFS_ADMIN_USR EXPIRED & LOCKED 已选择30行。 |
关于DBSNMP与SYSMAN的描述:--来自官方文档
DBSNMP |
DBSNMP 默认密码 |
The account used by the Management Agent component of Oracle Enterprise Manager to monitor and manage the database |
SYSMAN |
CHANGE_ON_INSTALL 默认密码 |
The account used to perform Oracle Enterprise Manager
database administration tasks. Note that SYS and SYSTEM can also perform
these tasks. |
6、使用RMAN备份数据库
1、切换服务器归档模式,如果已经是归档模式可跳过此步: %sqlplus /nolog (启动sqlplus) SQL> conn / as sysdba (以DBA身份连接数据库) SQL> shutdown immediate; (立即关闭数据库) SQL> startup mount (启动实例并加载数据库,但不打开) SQL> alter database archivelog; (更改数据库为归档模式) SQL> alter database open; (打开数据库) SQL> alter system archive log start; (启用自动归档) SQL> exit (退出) |
1、在开始菜单运行cmd命令: Microsoft Windows [版本 6.1.7601] 版权所有 (c) 2009 Microsoft Corporation。保留所有权利。 C:\Users\Administrator> sqlplus /nolog SQL*Plus: Release 11.2.0.1.0 Production on 星期五 5月 29 10:35:41 2015 Copyright (c) 1982, 2010, Oracle. All rights reserved. SQL> conn / as sysdba 已连接。 SQL> shutdown immediate; 数据库已经关闭。 已经卸载数据库。 ORACLE 例程已经关闭。 SQL> startup mount ORACLE 例程已经启动。 Total System Global Area 1068937216 bytes Fixed Size 2182592 bytes Variable Size 633340480 bytes Database Buffers 427819008 bytes Redo Buffers 5595136 bytes 数据库装载完毕。 SQL> alter database archivelog; 数据库已更改。 SQL> alter database open; 数据库已更改。 SQL> alter system archive log start; 系统已更改。 SQL>exit 从 Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options 断开 |
2、连接: rman target=sys/1@orcl; (启动恢复管理器) |
继续在推出命令框中输入RMAN的命令 C:\Users\Administrator>rman target=sys/1@orcl; 恢复管理器: Release 11.2.0.1.0 - Production on 星期五 5月 29 10:52:49 2015 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. 连接到目标数据库: ORCL (DBID=1408432054) RMAN> |
3、基本设置: RMAN> configure default device type to disk; (设置默认的备份设备为磁盘) RMAN> configure device type disk parallelism 2; (设置备份的并行级别,通道数) RMAN> configure channel 1 device type disk fromat ‘/backup1/backup_%U‘; (设置备份的文件格式,只适用于磁盘设备) RMAN> configure channel 2 device type disk fromat ‘/backup2/backup_%U‘; (设置备份的文件格式,只适用于磁盘设备) RMAN> configure controlfile autobackup on; (打开控制文件与服务器参数文件的自动备份) RMAN> configure controlfile autobackup format for device type disk to ‘/backup1/ctl_%F‘; (设置控制文件与服务器参数文件自动备份的文件格式) 4、查看所有设置: RMAN> show all 5、查看数据库方案报表: RMAN> report schema; 6、备份全库: RMAN> backup database plus archivelog delete input; (备份全库及控制文件、服务器参数文件与所有归档的重做日志,并删除旧的归档日志) 7、备份表空间: RMAN> backup tablespace system plus archivelog delete input; (备份指定表空间及归档的重做日志,并删除旧的归档日志) 8、备份归档日志: RMAN> backup archivelog all delete input; 9、复制数据文件: RMAN> copy datafile 1 to ‘/oracle/dbs/system.copy‘; 10、查看备份和文件复本: RMAN> list backup; 11、验证备份: RMAN> validate backupset 3; 12、从自动备份中恢复服务器参数文件: RMAN> shutdown immediate; (立即关闭数据库) RMAN> startup nomount; (启动实例) RMAN> restore spfile to pfile ‘/backup1/mydb.ora‘ from autobackup; (从自动备份中恢复服务器参数文件) 13、从自动备份中恢复控制文件: RMAN> shutdown immediate; (立即关闭数据库) RMAN> startup nomount; (启动实例) RMAN> restore controlfile to ‘/backup1‘ from autobackup; (从自动备份中恢复控制文件) 13、恢复和复原全数据库: RMAN> shutdown immediate; (立即关闭数据库) RMAN> exit (退出) %mv /oracle/dbs/tbs_12.f /oracle/dbs/tbs_12.bak (将数据文件重命名) %mv /oracle/dbs/tbs_13.f /oracle/dbs/tbs_13.bak (将数据文件重命名) %mv /oracle/dbs/tbs_14.f /oracle/dbs/tbs_14.bak (将数据文件重命名) %mv /oracle/dbs/tbs_15.f /oracle/dbs/tbs_15.bak (将数据文件重命名) %rman target=rman/rman@mydb (启动恢复管理器) RMAN> startup pfile=/oracle/admin/mydb/pfile/initmydb.ora (指定初始化参数文件启动数据库) RMAN> restore database; (还原数据库) RMAN> recover database; (恢复数据库) RMAN> alter database open; (打开数据库) 14、恢复和复原表空间: RMAN> sql ‘alter tablespace users offline immediate‘; (将表空间脱机) RMAN> exit (退出恢复管理器) %mv /oracle/dbs/users01.dbf /oracle/dbs/users01.bak (将表空间重命名) %rman target=rman/rman@mydb (启动恢复管理器) RMAN> restore tablespace users; (还原表空间) RMAN> recover tablespace users; (恢复表空间) RMAN> sql ‘alter tablespace users online‘; (将表空间联机) |
RMAN> configure default device type to disk; 使用目标数据库控制文件替代恢复目录 新的 RMAN 配置参数: CONFIGURE DEFAULT DEVICE TYPE TO DISK; 已成功存储新的 RMAN 配置参数 RMAN> configure device type disk parallelism 2; 新的 RMAN 配置参数: CONFIGURE DEVICE TYPE DISK PARALLELISM 2 BACKUP TYPE TO BACKUPSET; 已成功存储新的 RMAN 配置参数 RMAN> configure channel 1 device type disk fromat ‘c:/backup1/backup_%U‘; 新的 RMAN 配置参数: CONFIGURE CHANNEL 1 DEVICE TYPE DISK FORMAT ‘/backup1/backup_%U‘; 已成功存储新的 RMAN 配置参数 RMAN> configure channel 2 device type disk format ‘/backup2/backup_%U‘; 新的 RMAN 配置参数: CONFIGURE CHANNEL 2 DEVICE TYPE DISK FORMAT ‘/backup2/backup_%U‘; 已成功存储新的 RMAN 配置参数 RMAN> configure controlfile autobackup on; 旧的 RMAN 配置参数: CONFIGURE CONTROLFILE AUTOBACKUP OFF; 新的 RMAN 配置参数: CONFIGURE CONTROLFILE AUTOBACKUP ON; 已成功存储新的 RMAN 配置参数 RMAN> configure controlfile autobackup format for device type disk to‘/backup1/ctl_%F‘; 旧的 RMAN 配置参数: CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO ‘%F‘; 新的 RMAN 配置参数: CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO ‘/backup1/ctl_%F‘; 已成功存储新的 RMAN 配置参数 RMAN> show all; db_unique_name 为 ORCL 的数据库的 RMAN 配置参数为: CONFIGURE RETENTION POLICY TO REDUNDANCY 1; CONFIGURE BACKUP OPTIMIZATION OFF; CONFIGURE DEFAULT DEVICE TYPE TO DISK; CONFIGURE CONTROLFILE AUTOBACKUP ON; CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO ‘/backup1/ctl_%F‘; CONFIGURE DEVICE TYPE DISK PARALLELISM 2 BACKUP TYPE TO BACKUPSET; CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; CONFIGURE CHANNEL 2 DEVICE TYPE DISK FORMAT ‘/backup2/backup_%U‘; CONFIGURE CHANNEL 1 DEVICE TYPE DISK FORMAT ‘/backup1/backup_%U‘; CONFIGURE MAXSETSIZE TO UNLIMITED; CONFIGURE ENCRYPTION FOR DATABASE OFF; CONFIGURE ENCRYPTION ALGORITHM ‘AES128‘; CONFIGURE COMPRESSION ALGORITHM ‘BASIC‘ AS OF RELEASE ‘DEFAULT‘ OPTIMIZE FOR LOA D TRUE ; # default CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; CONFIGURE SNAPSHOT CONTROLFILE NAME TO ‘C:\APP\ADMINISTRATOR\PRODUCT\11.2.0\DBHO ME_1\DATABASE\SNCFORCL.ORA‘; RMAN> report schema; db_unique_name 为 ORCL 的数据库的数据库方案报表 永久数据文件列表 =========================== 文件大小 (MB) 表空间 回退段数据文件名称 ---- -------- -------------------- ------- ------------------------ 1 680 SYSTEM *** C:\APP\ADMINISTRATOR\ORADATA\ORCL\SYS TEM01.DBF 2 490 SYSAUX *** C:\APP\ADMINISTRATOR\ORADATA\ORCL\SYS AUX01.DBF 3 70 UNDOTBS1 *** C:\APP\ADMINISTRATOR\ORADATA\ORCL\UND OTBS01.DBF 4 5 USERS *** C:\APP\ADMINISTRATOR\ORADATA\ORCL\USE RS01.DBF 临时文件列表 ======================= 文件大小 (MB) 表空间 最大大小 (MB) 临时文件名称 ---- -------- -------------------- ----------- -------------------- 1 29 TEMP 32767 C:\APP\ADMINISTRATOR\ORADATA\ORCL\TEMP01.DBF RMAN> |
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。