Running SQL scripts with MySQL

Here’s another of those little things that you forget if you aren’t using them every day: running MySQL scripts using the Windows command line. Yes, you can also run SQL commands interactively but there’s a certain convenience about scripts. I am putting an example here so that it can be found again easily:

mysql -u username -p databasename < script.sql

I wouldn’t be at all surprised if the same line worked under Linux and UNIX but I haven’t needed to give it a try.

Leave a Reply