For mysql you can use option file read from reference1, reference2 You can set values like username and password
[db-details]
user=username
password=password
and read this file for logging in to db in script. and to avoid anyone else read it except root, just the permissions as
chmod 600 option_file