pdufault/mysqlfragfinder — Issue #4: Escape database name
Author: vlastikcz
Created: 2012-01-26 22:11:32+00:00
State: open

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)

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