To execute the contents of a query file 'exec.sql' by feeding it to mysql, which command is used?
A. mysql exec.sql > sampdb
B. mysql sampdb < exec.sql
C. mysql exec.sql
D. mysql exec
Answer: Option B
Solution (By Examveda Team)
This question is about how to run a SQL query file in MySQL. Think of it like giving your computer a list of instructions to follow. The file 'exec.sql' contains these instructions.Let's break down the options:
Option A: mysql exec.sql > sampdb
This option tries to run the 'exec.sql' file and then redirect the output (results of the queries) to a file named 'sampdb'. This is not the correct way to run a query file.
Option B: mysql sampdb < exec.sql
This option is the correct answer! It tells MySQL to connect to the database named 'sampdb' and then read the commands from the 'exec.sql' file. Think of the '<' symbol as directing the contents of 'exec.sql' into MySQL.
Option C: mysql exec.sql
This option tries to run the file 'exec.sql' but doesn't specify which database to use. It's incomplete.
Option D: mysql exec
This option only tries to connect to MySQL and doesn't mention the query file 'exec.sql'.
So, the answer is Option B: mysql sampdb < exec.sql. This is how you tell MySQL to use the instructions in the 'exec.sql' file on the database named 'sampdb'.

Join The Discussion