0

I created a little script which must change engine for tables:

#!/bin/bash

echo "use test_1;" > query.sql

get_list () {
mysql -u teamcity -ppassword -B -N -e 'show tables like "%"' test_1 | xargs -I '{}'     echo "alter table {} engine=innodb;" >> query.sql
}

get_list ;

mysql -u teamcity -ppassword < query.sql

But - how can I avoid use query.sql file? I make few attempts with "Here document" - but can't solve it...

For example - trying this:

#!/bin/bash

get_list () {
mysql -u teamcity -ppassword -B -N -e 'show tables like "%"' test_1 | xargs -I '{}'     echo "alter table {} engine=innodb;"
}

a="$(get_list)"
b="use test_1;"
c="$b $a"

mysql -u teamcity -ppassword <<< $c

But it is not working...

1 Answer 1

3

Put everything in a function and pipe that:

#!/bin/bash
get_list () {
  echo "use test_1;"

  mysql -u teamcity -ppassword -B -N -e 'show tables like "%"' test_1 | xargs -I '{}' echo "alter table {} engine=innodb;"
}

get_list | mysql -u teamcity -ppassword 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.