分类: 系统运维
2011-08-12 17:43:02
要让标准InnoDB Monitor写到mysqld的标准输出,请使用下列SQL语句:
CREATE TABLE innodb_monitor(a INT) ENGINE=INNODB;监视器可以通过发出下列语句来被停止:
DROP TABLE innodb_monitor;比如需要观察show innodb status、innodb_tablespace_monitor、innodb_lock_monitor、 innodb_table_monitor这些命令在某个时间段的信息,如果要手动重复执行很麻烦,而innodb引擎在设计的时候就已经考虑到了,不过 不够灵活,方法如下:
在数据库中创建相应引擎为innodb的表,创建相应的表之后,每15秒输出一次相应的信息到mysql error log中,不需要此功能的时候,删除相应的表即可,语句如下:
mysql> create table innodb_monitor(a int) engine=innodb;
Query OK, 0 rows affected (0.00 sec)
mysql> create table innodb_tablespace_monitor (a int) engine=innodb;
Query OK, 0 rows affected (0.01 sec)
mysql> create table innodb_lock_monitor (a int) engine=innodb;
Query OK, 0 rows affected (0.01 sec)
mysql> create table innodb_table_monitor (a int) engine=innodb;
Query OK, 0 rows affected (0.01 sec)
其实在Linux中,利用watch命令更加灵活地实现上面的需求,例如:每30秒输出一次show innodb status的结果,并把结果保存在一个文件中,语句如下:
[root@youxia205 tmp]# watch -n 30 'mysql -uroot -padmin -e "show innodb status\G" >> ;
关于watch命令的详细用法,可以查询man手册。
(none)_root >\s
--------------
mysql Ver 14.14 Distrib 5.5.9, for linux2.6 (x86_64) using readline 5.1
Connection id: 814935
Current database:
Current user: [email=root@ciptestb352v]root@ciptestb352v[/email]
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.5.9-log MySQL Community Server (GPL)
Protocol version: 10
Connection: 3.239.32.73 via TCP/IP
Server characterset: latin1
Db characterset: latin1
Client characterset: utf8
Conn. characterset: utf8
TCP port: 7780
Uptime: 126 days 9 hours 6 min 7 sec
Threads: 31 Questions: 422682422 Slow
queries: 16486 Opens: 676841 Flush tables: 6932 Open tables:
207 Queries per second avg: 38.710
--------------
(none)_root >SHOW PLUGINS
-> ;
+-----------------------+----------+--------------------+---------+---------+
| Name | Status | Type | Library | License |
+-----------------------+----------+--------------------+---------+---------+
| binlog | ACTIVE | STORAGE ENGINE | NULL | GPL |
| mysql_native_password | ACTIVE | AUTHENTICATION | NULL | GPL |
| mysql_old_password | ACTIVE | AUTHENTICATION | NULL | GPL |
| CSV | ACTIVE | STORAGE ENGINE | NULL | GPL |
| MRG_MYISAM | ACTIVE | STORAGE ENGINE | NULL | GPL |
| MyISAM | ACTIVE | STORAGE ENGINE | NULL | GPL |
| MEMORY | ACTIVE | STORAGE ENGINE | NULL | GPL |
| FEDERATED | DISABLED | STORAGE ENGINE | NULL | GPL |
| BLACKHOLE | ACTIVE | STORAGE ENGINE | NULL | GPL |
| InnoDB | ACTIVE | STORAGE ENGINE | NULL | GPL |
| INNODB_TRX | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_LOCKS | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_LOCK_WAITS | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_CMP | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_CMP_RESET | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_CMPMEM | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| INNODB_CMPMEM_RESET | ACTIVE | INFORMATION SCHEMA | NULL | GPL |
| ARCHIVE | ACTIVE | STORAGE ENGINE | NULL | GPL |
| PERFORMANCE_SCHEMA | ACTIVE | STORAGE ENGINE | NULL | GPL |
| partition | ACTIVE | STORAGE ENGINE | NULL | GPL |
+-----------------------+----------+--------------------+---------+---------+
20 rows in set (0.00 sec)
(none)_root >show status like '%lock%';
+------------------------------------------+-----------+
| Variable_name | Value |
+------------------------------------------+-----------+
| Com_lock_tables | 0 |
| Com_unlock_tables | 0 |
| Innodb_row_lock_current_waits | 0 |
| Innodb_row_lock_time | 3044731 |
| Innodb_row_lock_time_avg | 7847 |
| Innodb_row_lock_time_max | 51866 |
| Innodb_row_lock_waits | 388 |
| Key_blocks_not_flushed | 0 |
| Key_blocks_unused | 0 |
| Key_blocks_used | 214342 |
| Performance_schema_locker_lost | 0 |
| Performance_schema_rwlock_classes_lost | 0 |
| Performance_schema_rwlock_instances_lost | 0 |
| Qcache_free_blocks | 237 |
| Qcache_total_blocks | 24958 |
| Table_locks_immediate | 595571894 |
| Table_locks_waited | 4483 |
+------------------------------------------+-----------+
17 rows in set (0.00 sec)