Database size (MySQL)

Uit De Vliegende Brigade
Naar navigatie springen Naar zoeken springen

Some examples to monitor size of MySQL or MariaDB databases:

sudo du -sh /var/lib/mysql

sudo du -sh /var/lib/mysql/example_com

sudo ls -alFhS /var/lib/mysql/example_com

sudo ls  -alFhS example_com/wp_options.ibd

Within script, I use this function to fetch relevant information from all sites on a server:

   out1=$(sudo du -sh /var/lib/mysql/${site_array[$i,db]} | cut -f1)
   out2=$(sudo du -s /var/lib/mysql/${site_array[$i,db]} | cut -f1)
   out3=$(sudo du -sh /var/lib/mysql/${site_array[$i,db]}/wp_options.ibd | cut -f1)
   out4=$(sudo du -s /var/lib/mysql/${site_array[$i,db]}/wp_options.ibd | cut -f1)

   echo "${site_array[$i,db]}   ${site_array[$i,tag]}   ${out1}   ${out2}   ${out3}   ${out4}"

Subsequently, output is copy-pasted in a spreadsheet.

  • The columns with human-readible are used for just that
  • The actual number columns are used for sorting (you can't sort on human-readible numbers)
  • The actual number columns are also used for calculating the ratio of size of table wp_options as part of the whole db size.