I want to login to a database by running an SQL file from a Unix script without supplying username and password (as root). Is this possible?
The database is Oracle.
You can define your database users as being OS Authenticated. Tim Hall's Oracle_Base site has a good primer on how to do this. You don't need to allow folks to log in with SYSDBA privileges, a recipe for disaster.
If your user is in the oracle group, he can connect as SYSDBA.
Example on a Unix env:
$ export ORACLE_SID=MYDB
$ sqlplus /nolog
SQL*Plus: Release...
SP2-0640: Not connected
sql> connect / as sysdba
Connected
SQL> select * from scott.employees ;
That might be something of an overkill for a batch (besides the fact that you have all privileges to screw up your db).
However AFAIK, that's the only option.
UPDATE Given DCookie's answer, this is not the only way. And as I already mentioned and underlined by DCookie this is a very risky path.
When you start SQL*Plus, you need a username and password to login to an Oracle Database schema. Your username and password identify you as an authorized user of the Oracle Database schema.
The database administrator (DBA) is responsible for creating your database account with the necessary privileges and giving you the username and password that enables you to access your account.
If using PostgreSQL then you can specify the "trust" method for your localhost network in the "pg_hba.conf" file. For MySQL there may be something similar, I'm not sure (hopefully someone here who's familiar with whatever database you're using can help with this if it's not PostgreSQL).