Store mysql query output into a shell variable

前端 未结 11 1342
暗喜
暗喜 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 07:00

    Another example when the table name or database contains unsupported characters such as a space, or '-'

    db='data-base'
    
    db_d=''
    db_d+='`'
    db_d+=$db
    db_d+='`'
    
    myvariable=`mysql --user=$user --password=$password -e "SELECT A, B, C FROM $db_d.table_a;"`
    

提交回复
热议问题