Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8069039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:53:06+00:00 2026-06-05T12:53:06+00:00

I have to write a small multithreaded mysqldump script for our database and I

  • 0

I have to write a small multithreaded mysqldump script for our database and I got some problems because of a single table containing a space.

My first attempt was quite easy:

for TABLE in `mysql -u user -ppassword -e 'show tables;' dbname`  
do
    while [ 1 ]
    do
        if [ `jobs -r | wc -l` -lt $MAXTHREADS ]
        then
            break
        else
            sleep 1
        fi
    done

    mysqldump -u user -ppassword dbname $TABLE
done

Unfortunetely there was a table which contained a space. I googled a little bit for using the for loop with multiline output from commands and changing the $IFS variable was a common solution. So I changed it to \n\b (somehow $IFS was empty when I only used \n) but that was a bad idea because it caused the mysql commands to not work anymore.

I thought that this shouldn’t be a problem when I get the tables beforehand and change the $IFS back everytime I use mysqldump in the for loop. But again I was mistaken as I only have one line of all tables now.
My current code:

TABLES=$(mysql -u user -ppassword -e "show tables" dbname | tail -n +2)

OIFS="$IFS"
AIFS=$(echo -en "\n\b")
IFS="$AIFS"

for TABLE in "$TABLES"
do
    IFS="$OIFS"
    while [ 1 ]
    do
        if [ `jobs -r | wc -l` -lt $MAXTHREADS ]
        then
            break
        else
            sleep 1
        fi
    done

    mysqldump -u user -ppassword dbname $TABLE
    IFS="$AIFS"

done
IFS="$OIFS"

When I try to echo the $TABLES variable I get one table per line, but the for loop is only running once with the $TABLE variable containing ALL the tables.

Thanks in advance
kiro

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T12:53:08+00:00Added an answer on June 5, 2026 at 12:53 pm

    Use a while loop instead of for:

    mysql -u user -ppassword -e "show tables" dbname | tail -n +2 | while read TABLE
    do
        ...
    done
    

    …unless you need to set any variables inside the loop and have them available after the loop exits. Since this makes the while loop part of a pipeline, it runs in a subshell, and variables and such don’t transfer to the main shell. If you need the loop to run in the main shell, you can use bash’s process substitution feature instead of a standard pipe:

    while read TABLE
    do
        ...
    done < <(mysql -u user -ppassword -e "show tables" dbname | tail -n +2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have to write small java database application with several tables. With that i
I have to write a small app which downloads a few thousand files. Some
I'm trying to write a small application and have come across a compile time
I have an assignment about fftw and I was trying to write a small
Right now I have been trying to use Launchpad's API to write a small
This is Uday. I have a problem with the write performance with a small
I have been reading about Scala for a while and even wrote some small
I have this small PHP script that takes a POST variable and writes it
I have write a small python module with one class and two functions. The
I have to write several small vertical gradients (on a loop) and so I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.