Shell - one line query

前端 未结 6 1600
天命终不由人
天命终不由人 2021-02-07 02:01

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\' <          


        
6条回答
  •  温柔的废话
    2021-02-07 02:18

    I normally prefer Triple less then as its syntax and approach is similar to file redirect. Easy to go back in history and modify query

    mysql database --user='root' --password='my-password' <<< "UPDATE `database` SET `field1` = '1' WHERE `id` = 1111"
    

    It is called Here Strings in bash. You can find more about them here http://linux.die.net/abs-guide/x15683.html

    It is useful when you want to pipe string to commands.

提交回复
热议问题