最近也是因为项目接触了一下啊oracle,接触了也遇到了一些问题,写下来一是分享而是避免下次再花费相同的时间解决相同的问题:
启停数据库
// 停止数据库实例 sqlplus / as sysdba // 进入sqlplus后,关闭数据库 shutdown immediate // 启动数据库命令 startup // 退出 exit
监听服务
// 查看状态 lsnrctl status // 停止监听服务 lsnrctl stop // 启动监听服务 lsnrctl start // 查看服务 lsnrctl service
sqlplus相关配置
set linesize 200; set pagesize 30; set heading off; //登录 sqlplus test/[email protected]:1521/orcl
sqlplus脚本相关
表空间相关创建表空间
//单个文件不能超过32G,总文件数不能超过db_files参数 create tablespace sxdata2 logging datafile '/mnt/data2/oradata/sxdata.dbf' size 10000m autoextend on next 200m maxsize 3500000m extent management local; // 增加表空间文件 add tablespace sxdata2 datafile '/mnt/data2/oradata/sxdata1.dbf' size 10000m autoextend on next 200m maxsize 3500000m; // bigfile创建的表空间不受单个文件32G的限制,但不能增加datafile create bigfile tablespace sxdata2 logging datafile '/mnt/data2/oradata/sxdata.dbf' size 10000m autoextend on next 200m maxsize 3500000m extent management local;
查看表空间
select username, default_tablespace from dba_users; // 查看用户表空间 select USERNAME,DEFAULT_TABLESPACE from dba_users where USERNAME='';
查看表数据量
select bytes/1024/1024 as "MB",segment_name from user_segments group by segment_name;
创建DBLINK
create public database link qhfklink connect to myusername identified by 123456 using '(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.1.10)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = orcl)))';
用户相关创建用户、授权
CREATE USER dbtest IDENTIFIED BY 123456 ; grant resource,connect,dba to dbtest;
impdp expdp创建数据目录、授权
CREATE DIRECTORY dumptest AS ‘/home/oracle/dbtest’;
GRANT READ,WRITE ON DIRECTORY dumptest TO dbtest;
创建测试数据
create table t1 (id int);
insert into t1 values (123);
创建物理数据目录,导出
mkdir /home/oracle/dbtest
按照表导出
expdp dbtest/123456@orcl directory=dumptest dumpfile=test.dmp tables=t1
其他示例(待整理)
1)按用户导 expdp scott/tiger@orcl schemas=scott dumpfile=expdp.dmp DIRECTORY=dpdata1; 2)并行进程parallel expdp scott/tiger@orcl directory=dpdata1 dumpfile=scott3.dmp parallel=40 job_name=scott3 3)按表名导 expdp scott/tiger@orcl TABLES=emp,dept dumpfile=expdp.dmp DIRECTORY=dpdata1; 4)按查询条件导 expdp scott/tiger@orcl directory=dpdata1 dumpfile=expdp.dmp Tables=emp query='WHERE deptno=20'; 5)按表空间导 expdp system/manager DIRECTORY=dpdata1 DUMPFILE=tablespace.dmp TABLESPACES=temp,example; 6)导整个数据库 expdp system/manager DIRECTORY=dpdata1 DUMPFILE=full.dmp FULL=y;
导入数据
导入前,删除dbtest用户下的t1表,测试导入;
impdp dbtest/123456@orcl directory=dumptest dumpfile=test.dmp tables=t1
参考
字符集相关查看服务端字符集
select * from nls_database_parameters;
设置客户端字符集
export NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK"