I am trying to login to my database using sqlplus command. So I passed my username(aryan) and password(12345) but it says invalid username/password
But when I am asked to manually enter same user-name and password, I am logged in successfully. I have no idea what's wrong
bash-4.4$
sqlplus aryan/12345@localhost:1521/ORCLPDB1
SQL*Plus: Release 19.0.0.0.0 - Production on Sat Feb 24 03:37:54 2024
Version 19.19.0.0.0
Copyright (c) 1982, 2023, Oracle. All rights reserved.
ERROR:
ORA-01017: invalid username/password; logon denied
Enter user-name: aryan
Enter password:
Last Successful login time: Fri Feb 23 2024 18:10:39 +00:00
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.19.0.0.0
SQL>
How can I login with one line sqlplus command by passing username/password?
Local connections don't go through the listener, so they don't use a TNS string or connection string of any kind. They use the bequeath protocol whereby your client process becomes your database process (e.g. there is no separate shadow process like a listener-created connection makes). Because they don't go through the listener via TCP, they don't use a host, a port, or a service name.
Rather than the command line, your environment (principally
$ORACLE_SIDnaming the instance, but also requiring$ORACLE_HOME, a$PATHthat includes$ORACLE_HOME/binand in some cases also$LD_LIBRARY_PATHthat includes$ORACLE_HOME/lib) will determine which instance you connect to, as you can have multiple instances on the box, and which software installation/version to use (as you can have multiple software installations, and you must use the one that the instance is using).Set this environment either manually, in login scripts, or with
. oraenv(which you apparently already have, as you are able to connect in one of your tests), and then invokesqlplussimply with:sqlplus aryan/12345All by itself. Be aware though, you are putting your password on the command line, visible to anybody logged into the box who does a
psor anyone logging into the same OS account later and browsing command history. For scripting, far better to use/NOLOGand use a here-doc (simplest), or pipe in via stdin from a file to provide the login info:Here-doc:
Or file via stdin:
file contents:
And pipe it in:
Or
That way your password isn't part of the command string. Far safer.