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
After that, run the following command from the MySQL command prompt.
The above command will run all the available SQL queries on selected database (mydb in my case).