开发者

Pass result of Curl request to mysql command line

SO this is a bit of an odd request but hoping someone on here knows some command line fu. Might have to post to serverfault too, we'll see.

I'm trying to figure out how i can pass the results of a curl request to the mysql command line application. So basically something kinda like this -

mysql --user=root --password=my_pass < (curl http://localhost:3000/application.sql) 

where that URL returns basically a text response with sql statements.

Some context:

An application I am developing supports multiple installations, as part of the installation process for a new instance we spin up a copy of our "data" database for the new instance.

I'm trying to automate the deployment process as much as possible so I built a small "dashboard" app in rails that can generate the sql statements, config files, etc for each instance and also helps us see stats about the instances and other fun stuff. Now I'm writing capistrano tasks to actually do a deployment based on the ID of the installation which i pass in as a variable.

The initial deployment setup includes creating the applications database, which this sql request will do. I could in theory pull the file in a wget request, execut开发者_JAVA技巧e and delete it but I thought it would be cleaner to just tell the remote server to curl request it and execute it in one step.

So any ideas?


I'm fairly certain the syntax you have originally won't work as the '<' expects a file. Instead you want to pipe the output of curl, which by default prints to STDOUT to mysql. I believe the following will work for you.

curl http://localhost:3000/application.sql | mysql --user=root --password=my_pass 


In Bash, you can do process substitution:

mysql ... < <(curl ...)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜