Create you SQL script.
Once it is loaded into server run the following example command:
nohup mysql -u user-ppassword < script.sql > your_outputfile.out&
Note: there is no whitespace between -p and the password!
Using the above, it will write the output into the file you have decided, in our case your_ouputfile.out
Once this has been executed you get the PID, then to avoid process to die after closing the terminal just use the "disown" command like this: disown -h PID
Afterwards you can safely close your terminal and your process will continue executing in background.