Skip to content

How to Run SQL Text File on MySQL Command Prompt

How to Run SQL Text File on MySQL Command Prompt? How do I run a SQL text file on MySQL prompt? How to source .sql file on MySQL command prompt?

Category
Databases
Covers
MySQL
Versions & support
About MySQL →

Q. How do I run a SQL text file on MySQL prompt? How to source .sql file on MySQL command prompt? How do execute the .sql file in MySQL command prompt? How to Run SQL Text File on MySQL Command Prompt?

If you are on MySQL command prompt and need to execute all SQL queries contained in SQL file. You can simply do this by using source option to load any .sql file on your MySQL database. This executes all SQL queries available in a text file on selected database.

For example, you have a database schema file schema.sql to load on the database. Now login to MySQL server and select database.

$ mysql -u root -p

mysql> USE mydb;

After that, run the following command from the MySQL command prompt.

mysql> source /home/user/Downloads/schema.sql

The above command will run all the available SQL queries on selected database (mydb in my case).

Rahul

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top