Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress warning messages using mysql from within Terminal, but password written in bash script

Tags:

bash

shell

mysql

When I tried running the following command on MySQL from within Terminal:

mysql -u $user -p$password -e "statement" 

The execution works as expected, but it always issues a warning:

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

However, I have to conduct the statement above using an environment variable ($password) that stores my password, because I want to run the command iteratively in bash script from within Terminal, and I definitely don't like the idea of waiting a prompt showing up and forcing me to input my password 50 or 100 times in a single script. So here's my question:

  • Is it feasible to suppress the warning? The command works properly as I stated, but the window becomes pretty messy when I loop over and run the command 50 or 100 times.

  • Should I obey the warning message and do NOT write my password in my script? If that's the case, then do I have to type in my password every time the prompt forces me to do so?

Running man mysql doesn't help, saying only

--show-warnings
Cause warnings to be shown after each statement if there are any. This option applies to interactive and batch mode.

and mentions nothing about how to turn off the functionality, if I'm not missing something.

I'm on OS X 10.9.1 Mavericks and use MySQL 5.6 from homebrew.

like image 927
Blaszard Avatar asked Dec 23 '13 21:12

Blaszard


People also ask

How do I turn off warnings in mysql?

To suppress warnings, set SQL_NOTES=0.

How do I turn off warnings in Linux?

To suppress this warning use the unused attribute (Section 6.32 Specifying Attributes of Variables). To suppress this warning use the unused attribute (Section 6.32 Specifying Attributes of Variables). Warn whenever a statement computes a result that is explicitly not used.

How do I enable warnings in mysql?

"Query OK, 0 rows affected, 1 warning (0.07 sec)." "Empty set (0.00 sec)." as others have pointed out for interactive mysql you can, (1.) start the interactive session with the --show-warnings (see man mysql ) or (2.)


1 Answers

If your MySQL client/server version is a 5.6.x a way to avoid the WARNING message are using the mysql_config_editor tools:

mysql_config_editor set --login-path=local --host=localhost --user=username --password 

Then you can use in your shell script:

mysql --login-path=local  -e "statement" 

Instead of:

mysql -u username -p pass -e "statement" 
like image 170
Cristian Porta Avatar answered Sep 22 '22 01:09

Cristian Porta