Remote SSH to the Linux servers will get disconnected for multiple reasons, if you have a huge dump of MySQL database and want to restore the database using the MySQL command in the background and should not affect if your session terminates, follow the below steps
First, start your restore process using the usual MySQL command
ubuntu@ip-172-31-2-182:~$ mysql -u remote -p snappoint < snappoint.sql
when it is prompt, enter the relevant password at the MySQL command prompt for the mentioned user
Press Ctrl + z to suspend the current process ( MySQL Process which just started )
Then Run the bg command to move the above-suspended process to the background and resume its operation
ubuntu@ip-172-31-2-182:~$ bg
[1]+ mysql -u remote -p snappoint < snappoint.sql &
Run the jobs command to see the list of running processes in the current shell session, in my case I have only one process which is my MySQL
ubuntu@ip-172-31-2-182:~$ jobs
[1]+ Running mysql -u remote -p snappoint < snappoint.sql &
Lastly, disown the process, so that the process will not get killed if you exit the terminal or the session ends, use the command disown -h %<job-id>. In my case the job-id is 1
ubuntu@ip-172-31-2-182:~$ disown -h %1
Disclaimer: The scripts/code in this post are given as-is without any warranties. Please consider them as guidelines. Please don’t use them in your production environment until thoroughly testing them and making sure the processes work correctly.
Also published on Medium.