3

I am running Mysql 5.5.

I have about 100 Innodb tables spread over 10 DB's (mostly wordpress sites) and I am recently seeing a lot more disk IO than I have been, without any increase in traffic. The disk IO is from mysqld, and in monitoring mysqld, I am seeing what seem to me to be a lot of Innodb writes and specifically, I am seeing a lot of activity in the Innodb_rows_updated status variable that I can't easily explain.

Is there a way that I can determine which of the ~100 Innodb tables is having those rows updated?

LowlyDBA - John M
  • 10,922
  • 11
  • 42
  • 62
pjv
  • 191
  • 2
  • 7

1 Answers1

2

SINGLE DATABASE

DATABASE_TO_VIEW=mydb
cd /var/lib/mysql/$(DATABASE_TO_VIEW)
watch "ls -lt | grep ibd$ | head -20"

If you want just the table names

DATABASE_TO_VIEW=mydb
cd /var/lib/mysql/$(DATABASE_TO_VIEW)
watch "ls -lt | grep ibd$ | head -20 | awk '{print $9}' | sed 's/\.ibd//'"

MULTIPLE DATABASES

Create a script called /root/InnoDBChanges.sh with these lines

DATADIR=/var/lib/mysql
IBD1=/tmp/InnoDBFiles.txt
IBD2=/tmp/InnoDBFiles.srt
echo -n > ${IBD1}
cd ${DATADIR}
for DB in `ls -l | grep ^drw | awk '{print $9}' | grep -v mysql | grep -v performance_schema`
do
    FLDR=${DATADIR}/${DB}
    ls -l --time-style="+%s %Y-%m-%d %H:%M:%S" ${FLDR}/*.ibd|awk '{print $6,$7,$8,$9}' >> ${IBD1}
done
sort -nr < ${IBD1} > ${IBD2}
head -32 ${IBD2} | awk '{print $2,$3,$4}'

Then, you can monitor all the databases for changes at the same time

chmod +x /root/InnoDBChanges.sh
watch -n 5 /root/InnoDBChanges.sh

GIVE IT A TRY !!!

CAVEAT

If innodb_file_per_table is disabled, this will not work for you.

You will have to extract the tables from ibdata1. Then, you can try my solution.

STEP #1

Set innodb_file_per_table to 1 in /etc/my.cnf

[mysqld]
innodb_file_per_table = 1

STEP #2

service mysql restart

STEP #3

Convert every InnoDB table to InnoDB again

echo "SET SQL_LOG_BIN = 0;" > /root/ConvertInnoDBToInnoDB.sql
MYSQL_CONN="-u... -p..."
SQL="SELECT CONCAT('ALTER TABLE ',table_schema,'.',table_name,' ENGINE=InnoDB;')"
SQL="${SQL} FROM information_schema.tables WHERE engine='InnoDB'"
mysql ${MYSQL_CONN} -AN -e"${SQL}" >> /root/ConvertInnoDBToInnoDB.sql
less /root/ConvertInnoDBToInnoDB.sql

Once you view he script and are satisfied, login to mysql and run this

mysql> source /root/ConvertInnoDBToInnoDB.sql
RolandoMySQLDBA
  • 182,700
  • 33
  • 317
  • 520
  • hi, thanks. 2 things: 1. i have about 10 different DB's that i need to check on - the innodb tables are spread amongst them. 2. i get no output from the watch command. what is the "grep ibd$" for? - none of the tables have ibd as part of their filename. – pjv Jan 16 '15 at 18:31
  • Please run SHOW GLOBAL VARIABLES LIKE 'innodb_file_per_table';. What is it ??? – RolandoMySQLDBA Jan 16 '15 at 18:32
  • .ibd is the file extension of the physical file for any InnoDB table, provided you have innodb_file_per_table enabled. – RolandoMySQLDBA Jan 16 '15 at 18:35
  • innodb_file_per_table OFF - can i turn it on on a production DB without messing things up? – pjv Jan 16 '15 at 18:40
  • I have bad news for you. All the InnoDB data and index pages are inside /var/lib/mysql/ibdata1. My answer can only help if that is enabled and all the tables are extracted from it. – RolandoMySQLDBA Jan 16 '15 at 18:41
  • Got that. what will happen if i change that variable to ON and restart the server (i assume that is not a dynamic variable that i can change on the fly). ibdata1 = 202M – pjv Jan 16 '15 at 18:43
  • Nothing. It will let new tables be created in a separate file. All other tables are still inside ibdata1. See my post http://dba.stackexchange.com/questions/61116/migrate-from-innodb-file-per-table-to-off-in-mysql/61123#61123 on how to extract the files from ibdata1. The post tells you how to push all InnoDB tables inside ibdata1. Just set it to 1 any do the same thing and it will extract all the InnoDB tables. Be careful, you might neede some downtime for this one (depending on how much data you have). – RolandoMySQLDBA Jan 16 '15 at 18:46
  • Yup. Just fixed it. Thanks. I went back to my old post. and fixed it there as well. – RolandoMySQLDBA Jan 16 '15 at 19:11
  • ok, 202M of data in ibdata1. 100 lines (100 innodb tables) in ConvertInnoDBToInnoDB.sql. i really want to just run it but this is a production db. it's on a fast VPS with an SSD drive. do you think it's safe to run without doing a scheduled downtime and freaking out half a dozen fairly active bloggers? – pjv Jan 16 '15 at 19:26
  • Please go to my post http://dba.stackexchange.com/questions/8661/mysql-workbench-database-sizes/8662#8662 and run the first query. How much InnoDB data does it report ? – RolandoMySQLDBA Jan 16 '15 at 19:30
  • it says 0.085 GB – pjv Jan 16 '15 at 19:32
  • That's about 85M. You could probably do it fast, but someone will notice. Wait until activity dies down. Then go for it... – RolandoMySQLDBA Jan 16 '15 at 19:39
  • Rolando: thank you for the care, generosity, and amazing thoroughness of this answer. I just ran step #3 and I can now see which tables (there are 2 of them) are being modified constantly. Should make it relatively easy to track down what's causing it and fix it. A million thanks. – pjv Jan 17 '15 at 12:00