0

I am trying to execute a few mysql statements in bash script. The script connects to mysql and does all the required work. But, it gives me a warning

Warning: Using a password on the command line interface can be insecure.

I understand that passwords and usernames must not be used directly in the script, which I have currently done

What other options do I have in order to not have this warning coming up? Can I have a file with the key:value pairs for host,dbname,username and password and then use the file for connection details in the script?

Thanks in advance Rathi

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
Rathi Rao
  • 287
  • 1
  • 4
  • 19

1 Answers1

0

During the init phase of your script, I would ask the user for host, username and password. Then forward these variables to the mysql command.

See here where you can learn how to ask the user for content without echoing it on the terminal window.

Community
  • 1
  • 1
an.dr.eas.k
  • 151
  • 8
  • This script will be scheduled. And as per the requirement this does not require user intervention. So, how I automate in this case? – Rathi Rao Sep 28 '16 at 11:54
  • try this here http://stackoverflow.com/questions/20751352/suppress-warning-messages-using-mysql-from-within-terminal-but-password-written – an.dr.eas.k Sep 29 '16 at 07:39
  • Thanks that helped me . But, I get the Access denied error even after configuring mysql_config_editor. The link suggests in such cases I must configure in ~/.profile or ~/.bashrc files. If so, then what is the use of configuring mysql_config_editor ? – Rathi Rao Sep 29 '16 at 13:30
  • I guess, you're doing something wrong. Actually I have never used mysql-config-editor, but from the number of positive votes, I guess this procedure is fine. Check for updates of your mysql binaries. The method seems free from environment configs, thus I guess no extra .profile, or .bashrc is required – an.dr.eas.k Sep 30 '16 at 07:51
  • Sure ,thank you. I will check the updates. When you said, you are not using mysql_config_editor, how are you handling loading mysql credentials from a file? – Rathi Rao Oct 03 '16 at 06:44