How to run multiple sql statements at once from the command line

Tagged:  

In case you have to work from the command line (ssh?) and you need to run a lot of queries, instead of just running them one by one you can put your sql statements (inserts, updates, queries or whatever) and use:

shell> mysql db_name < text_file

If you have "use db_name" as your first line in your text_file you can just youse
shell> mysql < text_file

If you are in mysql you can use:
mysql> source file_name

You can find this in the mysql manual at the Executing SQL Statements from a Text File chapter.