How do you run a single query through mysql from the command line?

前端 未结 5 2009
旧巷少年郎
旧巷少年郎 2021-01-30 08:02

I\'m looking to be able to run a single query on a remote server in a scripted task.

For example, intuitively, I would imagine it would go something like:



        
5条回答
  •  渐次进展
    2021-01-30 08:19

    here's how you can do it with a cool shell trick:

    mysql -uroot -p -hslavedb.mydomain.com mydb_production <<< 'select * from users'
    

    '<<<' instructs the shell to take whatever follows it as stdin, similar to piping from echo.

    use the -t flag to enable table-format output

提交回复
热议问题