• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1048
  • 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
 
theGhost_k8Database 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
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

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