Store mysql query output into a shell variable

前端 未结 11 1322
暗喜
暗喜 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:54

    If you want to use a single value in bash use:

      companyid=$(mysql --user=$Username --password=$Password --database=$Database -s --execute="select CompanyID from mytable limit 1;"|cut -f1)
    
      echo "$companyid"
    

提交回复
热议问题