oracle、postgres、mysql数据库的建库、创建用户、导人导出备份总结

 

本文包含的内容:使用命令操作oracle、postgres、mysql的导入导出,包括登录到数据

注:我在公司使用的是Center OS操作系统,所以oracle和postgres均是在Linux使用,在其他工具中未测试;mysql是在自己的笔记本电脑上使用的,均在Linux和Dos命令下使用过。

1.oracle

  • 切换到oracle用户: su – oracle
  • 登陆数据库:sqlplus 用户名/密码@172.10.103.78:1521/orcl as sysdba;(用户名可使用系统的: sys)
  • 创建表空间:create tablespace 表空间名 datafile ‘/xx/xxx/xx.dbf‘ size 1000M autoextend on next 100M;
  • 创建用户:create user 用户名 identified by 密码 default tablespace 表空间;
  • 授权:grant connect,resource,dba to 用户名; (自己视情况而定)

  

  注:导出表之前可能需要进行空表的处理:

    select count(1) from user_tables where num_rows = 0;  –查询有多少个空表

    select ‘alter table  ‘ || table_name || ‘ allocate extent ; ‘ from user_tables where num_rows  = 0;

  •  导出:exp 用户名/密码@ip:sid/orcl  file=/xxx/xxx/xx.dmp   如:exp platform/platform@172.10.103.105:1521/orcl file=/data/oracle/platform_20180824.dmp;
  •  导入:imp 用户名/密码@ip:sid/orcl file=/xxx/xxx/xxx.dmp ignore=y full=y ;     如:imp platform/platform@172.10.103.105:1521/orcl file=/data/oracle/platform_20180824.dmp ignore=y full=y;

  

  其他操作

  •   查用户:select * from dba_users;
  •        查询使用表空间:select tablespace_name from user_tables group by tablespace_name;
  •        查询当前用户默认表空间:select default_tablespace from dba_users where username=‘用户名‘;
  •        查看表空间名,路径:select  t1.name, t2.name from v$tablespace t1, v$datafile t2 where t1.ts #=t2.tx#;

 2.postgres