I am trying to import a mysqldump file into my mysql database, but my (putty) connection to the server keeps timing out halfway through.

I tried to use nohup . . . . & but this doesn't appear to work.

My Command is

nohup sudo mysql -hlocalhost -P3306 -uxxxxxx -pxxxxxx < /var/lib/mysql/backups/dump.sql &

Which I believe should run it in the background, and persist after my connection to the server dies. However, when I then type jobs to see if it is running, it says:

    [1]   Stopped                 nohup sudo mysql -hlocalhost -P3306 -uxxxxx -pxxxxx < /var/lib/mysql/backups/dump.sql

Am I doing something wrong, or have I completely misunderstood the purpose of nohup . . . . &


sudo probably asks for a password and nohup disconnects the process from the controlling terminal. Use that instead:

sudo sh -c 'nohup mysql -hlocalhost -P3306 -uxxxxxx -pxxxxxx < /var/lib/mysql/backups/dump.sql &'
  • that's great cheers, it worked perfectly. – IGGt Jul 24 '15 at 12:16
  • This solution won't work if db password has special xters. The solution is to use quotes around the password, as per superuser.com/questions/123928/… – Mugoma J. Okomba Jun 19 '17 at 5:49
  • 1
    IMPORTANT!! This works perfectly, but note if an error occurs this will exit. add -f to force the insert. Having to start all over again isn't fun so I thought I'd share! – Yusaf Khaliq Sep 19 '17 at 14:22
  • Per Mugoma's comment above, the corrected command would be something like sudo sh -c "nohup mysql -hlocalhost -P3306 -uxxxxxx -p'x$$$xx' < /var/lib/mysql/backups/dump.sql &". Note change of single and double quotes. – a coder Jan 29 at 19:00

First, switch to root with

sudo -i


nohup sh -c 'mysql -hlocalhost -P3306 -uxxxxxx -pxxxxxx < /var/lib/mysql/backups/dump.sql' & 

I 'may' have solved this by leaving out the &, and then running nohup . . ., then pressing ctrl-z, then exiting from putty.

So far the MySQL connection appears to be still running

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.