Store mysql query output into a shell variable

前端 未结 11 1318
暗喜
暗喜 2020-12-01 06:14

I need a variable to hold results retrieved from the database. So far this is basically what I\'m trying with no success.

myvariable=$(mysql database -u $use         


        
11条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-01 06:41

    My two cents here:

    myvariable=$(mysql database -u $user -p$password -sse "SELECT A, B, C FROM table_a" 2>&1 \
       | grep -v "Using a password")
    

    Removes both the column names and the annoying (but necessary) password warning. Thanks @Dominic Bartl and John for this answer.

提交回复
热议问题