bash - SQL Query Outputs to variable

后端 未结 3 1563
悲&欢浪女
悲&欢浪女 2021-02-05 17:48

Im new in bash scripting. I want to save sql-query outputs in variable, but

actually I must connect for every query to mysql with:

mysql -u $MYUSER -p$MY         


        
3条回答
  •  迷失自我
    2021-02-05 18:35

    Another way of doing is:

    dbquery=`mysql -D$MYDB -u$MYUSER -p$MYPASS -se "SELECT domain FROM domains"`      
    dbquery_array=( $( for i in $dbquery ; do echo $i ; done ) )
    

    The first line stores all the output from the query in a varriable dbquery in a array-like-way. The second line converts the dbquery into an array dbquery_array with a simple for loop.

提交回复
热议问题