配置MYSQL 的AWR快照採集

一:在儲存採集信息的庫上執行快速安裝配置:
1,執行SQL腳本的內容:myawr.sql

二:在須要採集的數據庫上首先檢查是否安裝 perl-DBD-MySQL
rpm -qa perl-DBD-MySQL* mysql

沒有安裝的話直接 yum install perl-DBD-MySQL* 便可。 sql

1。檢查安裝模塊: 數據庫

[root@oel58 aaa]# cat listmodle.pl
#!usr/bin/perl
use strict;
use warnings; ide

use ExtUtils::Installed; fetch


my $inst = ExtUtils::Installed->new();
print join "\n", $inst->modules(); ip


[root@oel58 ~]# perl listmodle.pl
DBD::mysql
DBI
Perl 部署


2.檢查DBD的可用性: get

CREATE TABLE `test` (
  `name` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1; it

INSERT INTO test (name) VALUES ('hello world'); io


[root@oel58 ~]# cat dbd.pl
#!/usr/bin/perl

use DBI;

my $dbh = DBI->connect( "DBI:mysql:database=test;host=localhost",
 "root", "123456", { 'RaiseError' => 1 } );
#my $rows  = $dbh->do("INSERT INTO test (name) VALUES ('hello world')");
my $query = $dbh->prepare("SELECT name FROM test");
$query->execute();

while ( $ary = $query->fetchrow_arrayref() ) {
 print (  $ary->[0] . "\n");
}

3 初始化數據庫(注意:這個是在你要保存信息的mysql數據庫上部署)
增長配置信息:
INSERT INTO `myawr_host`(id,host_name,ip_addr,port,db_role,version, running_thread_threshold,times_per_hour) VALUES (6, 'db2.11', '192.168.3.11', 3306, 'master', '5.6.10',10000,0);

4. job(注意:這個是在你想要採集信息的mysql數據庫上部署):
grant all on *.* to 'superuser'@'localhost' identified by "111111";

5.在把下列腳本部署成job前,能夠先手工運行一下:

* * * * * perl /root/myawr/myawr.pl -u superuser -p 111111 -lh localhost -P 3306  -tu myuser -tp 111111 -TP 3306 -th 192.168.137.9 -n eth0 -d sda3 -I 6 >> /root/myawr/myawr_pl.log 2>&1


下面的腳本能夠模擬有lock wait的狀況:
use test;
create table txtest
(id int primary key ,
name varchar(200))
engine=innodb default charset = utf8 ;

insert into txtest values(1, 'xxxxxxxxxxxxxxxxxxxx');
insert into txtest values(2, 'zzzzzzzzzzzzzzzzzzzzzzz');
insert into txtest values(3, 'sssssssssssssssssssss');

commit;


###事物一
start transaction;
update txtest set name='ddddddddd' where id =1 ;

update txtest set name='wwwwwwwwwwwddddddddd' where id =2 ;

###事物二
start transaction;
update txtest set name='kkkkkkkkkkkkkkkkkk' where id =1 ;


###事物二
select sleep(300);


在把下列腳本部署成job前,能夠先手工運行一下:
 ./pt-query-digest --user=myuser --password=111111  --review h=192.168.137.9,D=myawr,t=myawr_query_review --review-history h=192.168.137.9,D=myawr,t=myawr_query_review_history --no-report --limit=100% --filter=" \$event->{add_column} = length(\$event->{arg}) and \$event->{hostid}=6"  /var/lib/mysql/oel58-slow.log

6 生成report:

perl myawrrpt.pl -u myuser -p 111111 -P 3306 -lh 192.168.137.9 -I 6 perl myawrsrpt.pl -u myuser -p 111111 -P 3306 -lh 192.168.137.9 -I 6 -s 29

相關文章
相關標籤/搜索