0

I want to save the query I wrote in mysql console to a .sql file... for example :

"CREATE TABLE Employee(id...,name...,salary);"

I want to save the code instead of it's result. thanks

Fatemeh Abdollahei
  • 3,040
  • 1
  • 20
  • 25

1 Answers1

0

Pass the query in a variable and then execute it. This way, variable will hold the query and you'll be able to do whatever you want:

  1. execute it
  2. send it to a file
  3. any other operation...

query="CREATE TABLE Employee(id...,name...,salary)";

mysql -u root -h localhost -P 3306 -p -e "$query"

echo $query >> query.sql

This'll print the data as well as populate a file query.sql in your PWD. The above example is a part of a shell script.

Yusuf Hassan
  • 1,933
  • 1
  • 12
  • 21