To connect databases through Unix




Unix Oracle Command

SURESH BABU KUNKU@SURESH ~
$ sqlplus system/suresh@xe

SQL*Plus: Release 11.2.0.2.0 Production on Sun Jan 29 09:35:32 2017

Copyright (c) 1982, 2010, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - Production

SQL>


To see the records in side table

SQL> select * from table_name;

To come out of SQL prompt

SQL> exit
Disconnected from Oracle Database 11g Express Edition Release 11.2.0.2.0 - Production


 Some example to send the sql file to mail through Unix command

cat myscript.sh
#!/bin/bash
 PATH=./u03/appl/home/suresh:${PATH}

sqlplus arbor/arbor123@f1pognl <<EOS
    SPOOL /u03/appl/farbat1/suresh/spool.out
setlinesize 2000
set wrap off
select sum(3+7) from dual;
    SPOOL OFF
exit
EOS
mail -s "sql file" sureshbabuk782@gmail.com< /u03/appl/home/suresh/spool.out


Unix MYSQL command

SURESH BABU KUNKU@SURESH ~
$ mysql -u username -p

To list the databases which exist, or:
mysql> USE dbname;
...to begin using the database named dbname, or:
mysql> SELECT  *  from  table_name;
...to display the tables_name of all records.
To end your mysql session and return to the shell prompt, use the command:
mysql> QUIT
Running MySQL Commands From A Batch Script
Instead of using mysql interactively, you can execute MySQL statements from a scriptfile. For instance, if you have a text file named mysqlscript.txt containing MySQL commands, one per line, you could use this command:
mysql -u username -p db_name < mysqlscript.txt > output.txt




EmoticonEmoticon