How to execute a MySQL command from a shell script?

前端 未结 14 1165
生来不讨喜
生来不讨喜 2020-11-28 01:28

How can I execute an SQL command through a shell script so that I can make it automated?

I want to restore data I have collected in a SQL file using a shell script.

14条回答
  •  庸人自扰
    2020-11-28 01:52

    All of the previous answers are great. If it is a simple, one line sql command you wish to run, you could also use the -e option.

    mysql -h  -u -p database -e \
      "SELECT * FROM blah WHERE foo='bar';"
    

提交回复
热议问题