[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1046
  • Last Modified:

how to create batch file -- i want run mysql query and write the result into .text file

how to create batch file -- i want run  mysql query and write the result into .text file
0
bowebell
Asked:
bowebell
2 Solutions
 
Kamaraj SubramanianApplication Support AnalystCommented:
0
 
bowebellAuthor Commented:
No i want excute qurery directly and write the result into text file ?

if possible i need to pass arguments to the script file too?
0
 
Kamaraj SubramanianApplication Support AnalystCommented:
0
 
K VDatabase ConsultantCommented:
Check following bat file:


@echo off
echo Parameter Passed - %1
mysql -uroot -ppass -e "query" > a.txt


This will output result of query to a.txt.
0
 
QlemoC++ DeveloperCommented:
For a single query, not to long, theGhost's answer is appropriate. If you have something longer, you could consider to use the way as posted in the last link, but IMHO better is this:

@echo off
(echo select *
 echo from table1
 echo where field1 = '%1';
) | mysql -uroot -ppass > result.txt

because you do not need any temporary files.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now