How can we run MySQL statements in batch mode?


We need to create a .sql file for running MySQL in batch mode. This file will contain the MySQL statements. Suppose I have hh.sql file in which I have written the statement select * from hh. With the help of the following command, we can run this file in batch mode −

Example

C:\Program Files\MySQL\bin>mysql -u root -p gaurav < hh.sql
Enter password: *****

Output

id
1
2

Here Gaurav is the database name that contains the table hh. Whenever you’ll run this command it will ask for the password and then give the output.

Updated on: 22-Jun-2020

268 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements