I need to execute a mysql query in one line using bash.
It should be something like this:
mysql database --user=\'root\' --password=\'my-password\' <
If you are running this on a production environment, it would be better to login to the mysql shell first so as not to expose your db details.
Once logged into shell, why not just use a prepared.sql file?
mysql -u user -p
Next, enter your user password
Now you are logged into shell and you can run commands securely from here:
mysql> use DBNAME mysql> SOURCE file.sql
This is how I operate on the command line with my databases in order for my passwords not to appear in the logs.