How to import and export the data from databse using shell script

Showing Answers 1 - 18 of 18 Answers

Mehraban

  • Mar 19th, 2007
 

Here's a sample shell script

sqlplus -s uname/passwd
<< EOF > data.log
select * from employees;
exit
EOF>

  Was this answer useful?  Yes

Guest

  • Mar 25th, 2007
 

#!/bin/sh
#set the environment
export ORACLE_SID=
export ORACLE_HOME=
export PATH=$ORACLE_HOME/bin:$HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib

Use the export syntax here

#Unset all the environment variables
unset ORACLE_SID
unset ORACLE_HOME
unset PATH
unset LD_LIBRARY_PATH

#Set the environmet variables for the database int which the data should be imported
export ORACLE_SID
export ORACLE_HOME
export PATH
export LD_LIBRARY_PATH

use the IMPORT syntax here

exit

<error condtion>

  Was this answer useful?  Yes

you can use the following command to take an export dump from the shell script.

exp [DBA user/DBA Password]  FILE= [FIle NAme] TABLES={All the table names]  ROWS=y log=indigo2.log


This will create the .dmp file in the current folder

  Was this answer useful?  Yes

Following command will be used for import from shell script

imp [DBA User/DBA Password] FILE= [File Name] FROMUSER=[User from which the dump is taken] TOUSER=i[user to which the dump will be imported]  TABLES= [table Name] log=[Log file name] ignore=y commit=Y

exp [User from whcih dump will be taken/ Password ] TABLES=[table name] FILE=[File Name] ROWS=y log=[Log file name]


  Was this answer useful?  Yes

Markerhell

  • Aug 26th, 2009
 

To import the data:
mysqldump -u username -p databasename >> databasenamedump.sql


To Export the data:
mysql -u username -p newdatabasename < databasenamedump.sql


  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions