Oracle基础

来自linux中国网wiki
跳到导航 跳到搜索

最常用的命令

#login 
su - oracle
[oracle@oracle-zimg-etc ~]$ sqlplus 
Enter user-name: sys as sysdba 
Enter password: 
SQL> 


一、首先创建一个表空间intratest

create tablespace intratest datafile '/home/oracle/app/oradata/xtwl/intratest.dbf' size 5m autoextend on next 50m maxsize unlimited;

exp ztgo0203/Ztgo_456@xtwl file=0203.dmp owner=ZTGO0203  #导出
imp ZTGO0816/ZTGO0816@xtwl file=0203.dmp fromuser=ZTGO0203 touser=ZTGO0816 #数据导入 xtwl数据库中
so 


ps:datafile可以通过查询视图v$dbfile获得:select * from v$dbfile;
如下  /home/oracle/app/oradata/xtwl/

 
二、创建一个用户orauserxk。最好是dba权限。默认表空间是intratest

create user orauserxk identified by 1234 default tablespace intratest temporary tablespace temp;
grant connect,resource ,dba  to orauserxk;


三、用imp命令导入

导入新库

#user is  oracle so  can user oracle user to imp  root files     touser  full 这两个mode 只能有其中一个 一般是基于用户的 所以不要 full=y
shell >imp orauserxk/1234@xtwl  file=./0203.dmp log=./imp.log fromuser=orauserxk  touser=orauserxk  ignore=y #

一般用 fromusr and touser
imp ZTGO/ZTGO@xtwl file=./1023.dmp  log=./log fromuser=zt touser=ZT 

导入非新库

 
ull=y ignore=y;  不然不成功

imp ZTGO0/ZTGO0@xtwl file=./1023.dmp full=y ignore=y;

oracle imp导入中文乱码

查看环境变量 echo $NLS_LANG

查看数据库字符集 select userenv('language') from dual;

SQL> select userenv('language') from dual;

USERENV('LANGUAGE')
----------------------------------------------------
AMERICAN_AMERICA.AL32UTF8

线上和开发环境看起来是一样的

如果二者不一致,修改其一使二者一致。

建议修改NLS_LANG,方便、简单、安全

修改NLS_LNAG,有两种方式

1,临时修改 在当前登录终端执行export NLS_LANG=XX (XX:表示数据库字符集)

   本地登录退出后失效
1
2,永久修改 修改.bash_profile,在文件中加入export NLS_LANG=XX (XX:表示数据库字符集)

 重新登录后永久生效
1
如果在设置环境变量的时候出现“XX: not a valid identifier”,检查XX中是否有空格,如果有空格要将XX用双引号包括。例如:export NLS_LANG=“SIMPLIFIED CHINESE_CHINA.ZHS16GBK”



数据库的字符集,与你导入的字符集一致吗? r如果不一致就会出现乱码情况

Oracle导入sql文件数据,中文乱码问题解决方案


acle imp导入中文乱码

四 exp 导出

#用户/密码@命名空间 
exp ztgo/Ztgo_6@xtwl file=1023.dmp owner=ZTGO0203

查看当前的所有数据库

select name from v$database;
select * from v$database; 

备份单张表

备份单张表,同时包含主键索引。
格式:
exp userid=myuserName/password  file=area20130613.dmp log=area20130613.log indexes=y compress=n tables=area;
eg:
#成功备份 备份目录  /home/evanbak 201810161445
exp ztgo0203/Ztgo_456@xtwl file=USER_MONEY_LAST.dmp  indexes=y compress=n tables=USER_MONEY_LAST;

exp ztgo0203/Ztgo_456@xtwl file=USER_MONEY_LAST.dmp owner=ZTGO0203 log=USER_MONEY_LAST.log indexes=y compress=n tables=USER_MONEY_LAST; #这个有错呀


恢复单张表。

imp myuserName/password file=area20130613.dmp tables=area;

修改oracle的用户的密码

普通用户

 sqlplus / as sysdba
 connect TGO0815/TGO0815

ALTER USER TGO0815 IDENTIFIED BY TDB0926;

查看表

describe nchar_tst(nchar_tst为表名)  # 哈哈 不是PT同学说的show tables

查询表的大小和表空间的大小

查询表的大小和表空间的大小

system、sys、

Oracle 用户、角色管理简介good

修改oracle的system、sys、普通用户的密码

oracle修改用户密码

Oracle 修改SYS、system用户密码

Oracle备份表exp和imp

see also

Oracle 全库备份脚本


oracle 全库 备份 导入

RedHat5.4安装oracle11g

oracle数据库数据导入导出步骤(入门)

oracle 快速删除大批量数据方法(全部删除,条件删除,删除大量重复记录)

Oracle快速清除表数据

oracle数据库删除数据的两种方式