To simply import a sql file (and get any results printed to the prompt)
mysql -uUSERNAME -p DBNAME < FILENAME
The parameters are
-u username (note no space between the u and USERNAME)
-p password (can be given as the username (without a space between p and PASSWORD; or if omitted mysql will ask for it)
DBNAME is the name of the database to import to (if the sql file don’t create a database on it’s own)
FILENAME is the name of the file to import
Other parameters can be
-h server host (dns name or ip) if -h is omitted then localhost is assumed.
-P port number
-f force (will not break on errors)
To import a sql file and then have to output to a file (for instance when running from a crontab)
mysql -uUSERNAME -p DBNAME < FILENAME > OUTFILE
Works just as the previous import except that any output will be written to OUTFILE.