Sample Header Ad - 728x90

MySQL: connect from console and hide password

0 votes
1 answer
58 views
I've been using the "mysql" command from the Unix console for a while now. It's more convenient for scheduling tasks or launching them unattended. The outline of a .sh script for this is: #!/bin/bash #DB Config USR_BD=myUsr PWD_BD=myPass IP_BD=x.x.x.x f_exec () { echo date ' -> Executing sql file ' $1 mysql -h $IP_BD -u $USR_BD -p$PWD_BD my_schema Executed sql file ' $1 } f_exec my_sentences.sql The thing is, I've passed a security check, and they tell me that I can't save the clear password in a variable, or in plain text file, inside a .sh script My question is: how can I solve this problem? - If you can save something like a token, the token presents the same problem as the password. - If you give permission to connect without a password to the host from which I run the script, if you gain access to that host, you also, consequently, gain access to the database. Of course, it is obvious that I am not going to connect at 3am to enter the password to run the script. Or waiting online for a 10 minutes long heavy query. I don't know how to solve the situation. Thanks.
Asked by yaki_nuka (155 rep)
Feb 13, 2025, 11:58 AM
Last activity: Feb 13, 2025, 04:56 PM