pdufault/mysqlfragfinder

Escape database name

Closed this issue · 3 comments

Hello,
your script doesn't work as expected on databases with special charasters like dash (the "-") in their name.

The problem is in this:
fragmented=( $("${mysqlCmd}" -u"$mysqlUser" -p"$mysqlPass" -h"$mysqlHost" --skip-column-names --batch -e "SHOW TABLE STATUS FROM $i;" 2>"$log" | awk '{print $1,$2,$10}' | egrep "MyISAM|InnoDB" | awk '$3 > 0' | awk '{print $1}') );

If the $i equals for example my-database, the query will end in error. you have to add escaped quotes like this:
fragmented=( $("${mysqlCmd}" -u"$mysqlUser" -p"$mysqlPass" -h"$mysqlHost" --skip-column-names --batch -e "SHOW TABLE STATUS FROM $i;" 2>"$log" | awk '{print $1,$2,$10}' | egrep "MyISAM|InnoDB|Aria" | awk '$3 > 0' | awk '{print $1}') );

(Adittionaly I added the Aria datastore, because I use it a lot and the OPTIMIZE works just like with the MyISAM)

However, I'm not sure how specific the problem is. Maybe it's just my problem :). But after this fix, script sucessfully optimizes all my databases. Before the fix, there was 90% of fragmented tables untouched.

Regards,
Vlastimil Kotas

I wasn't able to replicate the problem, but the wrapped `'s can't hurt. Technically it's more valid, so I'm happy to accept it. Please fork the repo and commit it, and submit a pull request. Thanks!

You need correct escaping for command-tags here.
I will make a pull request later on. Thank you!

DoesntMatter beat us to the punch! Thanks for the fix, DoesntMatter.