Guest User

Untitled

a guest
Jul 10th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. echo -n "MySQL username: " ; read username
  4. echo -n "MySQL password: " ; stty -echo ; read password ; stty echo ; echo
  5.  
  6. mysql -u $username -p"$password" -NBe "SHOW DATABASES;" | grep -v 'lost+found' | while read database ; do
  7. mysql -u $username -p"$password" -NBe "SHOW TABLE STATUS;" $database | while read name engine version rowformat rows avgrowlength datalength maxdatalength indexlength datafree autoincrement createtime updatetime checktime collation checksum createoptions comment ; do
  8. if [ "$datafree" -gt 0 ] ; then
  9. fragmentation=$(($datafree * 100 / $datalength))
  10. echo "$database.$name is $fragmentation% fragmented."
  11. mysql -u "$username" -p"$password" -NBe "OPTIMIZE TABLE $name;" "$database"
  12. fi
  13. done
  14. done
Add Comment
Please, Sign In to add comment