2

I need to run in background mode some mysql-query... But how can i do this with nohup?

Standardly i do:

mysql -uroot -p
use SomeDb;
Select * from blablalba;

But how can i do this with launching in db process? i do mysql importing with nohup, but how with query?

4 Answers 4

5
mysql -u [username] -p [database_name] -e "[sql_query]"

Example:

nohup mysql -u root -p somedb -e "select * from mytable" &
0

Thanks this helped However, I needed to enter a password after the command, so I did the following:

$ nohup mysql -u [username] -p [database_name] -e "[sql_query]"
Enter password:

Since I couldn't successfully run the command in the background, after entering the password at the prompt I closed my connection (by closing my remote console). I opened up a new session and it ran. It was a 3hr query with a spotty wireless connection, so this came in handy bigtime.

0
nohup mysql -u [username] -p[password] [database_name] -e "[sql_query]" &

Be sure to have the password follow the -p WITHOUT a space

0

I was having some timeout issues with the above solutions for some reason, but using the -c option seemed to fix it (Note that this also includes setting a password and redirecting the standard output and errors to a certain path):

nohup bash -c "mysql -u my_user --password='my_password' -e \"use SomeDb;  Select * from blablalba;\"" > my_file_path 2>&1 &

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .