Little bit late for the party, But myself struggled with this issue and found a solution and wanted to share.
Solution 1
Using screen is ideal for this situation as your processes will run even after you close your terminal.
sudo apt install screen
Open up a screen
screen
Now you can execute you command here and import the mysql db dump.
mysql -u username -p database_name < sqldump.sql
or
by simply login into your database and importing the file
source /var/www/html/db/my_database.sql;
To exit from the screen “ctrl + a + d”
you can list your available screens by
screen -ls
and simply open the screen by screen -r
when the job is done simply open the screen and use exit
command to close the screen.
Solution 2
Second way is to use nohup where I noticed sometime nohup also terminates when session closes. To sort that you have to use disown
nohup mysql -u'root' -p'password' databasename < sqldump.sql & > sql_load.log 2>sql_load_err.log disown %1