I am writing this on the train, so I’ll be relatively quick.
It’s been a while since I wrote my import sql file via command line post and thought I’d post the updated version which I now use.
It is possible to execute an SQL file without logging into the mysql client first. Previously, I used login to mysql and use the source command to execute commands from an SQL text file.
Now, I execute it all straight from bash or windows shell without having to login to the MySQL client.
To import an SQL file by passing it as if it were an arguement, you need to use the < sign. So for example, say that I wanted to import an external database from production and wanted to import it into my development environment, I can do so by doing the following:
How to Import an SQL file directly from the Command Line:
Step 1: Download the source sql file.
Step 2: Extract the SQL file sif required – usually, you’ll get the file in an archived form since an uncompressed SQL file is hideously large.
Step 3: Execute the following in the command line:
$ mysql -uusername -p -h databasehostname databasename < locally-extracted-sql-file.sql;
Step 4: Enter your password at the prompt.
Step 5: Check that your changes have been applied and make adjustments as required.
You should now see that the sql commands in the external file has been executed.
This is like general knowledge.
Not for everyone it ain’t Sammy.
Thanks this was super quick and easy. I can’t remember the exact commands so this is a great reference. Sammuy is a troll, forget him.