Using Capistrano To Run mySql Command -
I'm trying to use capistrano to run a mysql command.
If I run my local terminal then
mysql -u & lt; Username & gt; -P & lt; Password & gt; -H & LT; Server IP & gt; & Lt; Database Name & gt;
It connects to mysql and is ready for command.
If I run it in a Castrene task ....
"Mysql -u ", & lt; password & gt; -h & lt; server ip & gt; & lt; execute database name & gt; "
If it goes without fail and just hangs there does it mean Is that connected and waiting for an order? If so, how do I provide command?
mysql
The command line client has a few different ways, About the question command line it can accept them with the - execute / -e
flag:
mysql --execute 'SELECT * FROM tbl' --user = User dbname
or it can accept them from pipe or file redirection from STDIN
:
echo 'SELECT * FROM tbl '| Mysql --user = User dbname # or: mysql --user = user dbname & lt; File_containing_queries.sql
For your application in Capitolarano, you should work well to execute them through - execute
you have multiple semicolons You can delimit the statements, but quote everything properly. The complete set of SQL statements should be a quoted string.
# In a capistrano function: "mysql -e'chell 'to * tbl1; SELECT * fROM tbl2; -U & lt; username & gt; -p & lt; password & gt; ; -H & lt; server IP & gt; & lt; database name & gt; "
To prevent citing string literals inside SQL statements, alternate Good use of% q /% Q
can be:
execute % q {mysql -e "SELECT * FROM tbl1 WHERE col = 'value'; SELECT * FROM Tbl2 WHERE col = 'value'; " -U user-pseudost-host DBN name}
When launching the mysql
client via SSH in Capistorno, it appears that the client is loaded on the server MySQL offers - execute
and STDIN
for this reason, so they are used to accepting the statement, but they will be much more difficult to interactively eat. Would be best
Comments
Post a Comment