Store mysql query output into a shell variable

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

    If you have particular database name and a host on which you want the query to be executed then follow below query:

    outputofquery=$(mysql -u"$dbusername" -p"$dbpassword" -h"$dbhostname" -e "SELECT A, B, C FROM table_a;" $dbname)
    

    So to run the mysql queries you need to install mysql client on linux

提交回复
热议问题