HowTo: Use Oracle / MySQL SQL Commands In UNIX Shell Scripts

https:/‮www/‬.lautturi.com
HowTo: Use Oracle / MySQL SQL Commands In UNIX Shell Scripts

To use Oracle or MySQL SQL commands in a UNIX shell script, you can use the sqlplus or mysql command-line utilities, respectively. Both of these utilities allow you to execute SQL commands from the command line, and can be run from within a shell script to perform various database tasks.

To use sqlplus in a shell script, you can include a line like the following:

sqlplus username/password@database_name < sql_commands.sql

This will connect to the specified Oracle database using the provided username and password, and execute the SQL commands contained in the sql_commands.sql file.

To use mysql in a shell script, you can include a line like the following:

mysql -u username -p password -D database_name < sql_commands.sql

This will connect to the specified MySQL database using the provided username and password, and execute the SQL commands contained in the sql_commands.sql file.

Note that you will need to have the sqlplus or mysql utilities installed on your system in order to use them in your shell scripts. You may also need to set the appropriate permissions on the script file itself in order to execute it.

Created Time:2017-10-29 22:08:46  Author:lautturi