Pass parameters to MySQL script

后端 未结 6 2010
無奈伤痛
無奈伤痛 2020-12-09 04:05

I have a MySQL script file named query1.sql which contains:

select * FROM $(tblName) LIMIT 10;

I am in MySQL console, how do I

6条回答
  •  死守一世寂寞
    2020-12-09 04:08

    For bash scripting:

    tblName=$1 
    searchFor="%something%"
    
    echo "select * FROM $tblName LIMIT 10;
          select * From $tblName where somecolumn like '$searchFor';
    " | mysql
    

    For powershell:

    $tblName="MyTable"
    $searchFor="%something%"
    
    "select * FROM $tblName LIMIT 10;
      select * From $tblName where somecolumn like '$searchFor';
    " | mysql
    

提交回复
热议问题