-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathslowquery_explain_old.php
101 lines (87 loc) · 3.26 KB
/
slowquery_explain_old.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>慢查询日志</title>
<link rel="stylesheet" href="./css/simple-line-icons/css/simple-line-icons.css">
<link rel="stylesheet" href="./css/font-awesome/css/fontawesome-all.min.css">
<link rel="stylesheet" href="./css/styles.css">
</head>
<body>
<div class="card">
<div class="card-header bg-light">
详细的慢SQL语句是:
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover">
<?php
require 'SqlFormatter.php';
$checksum=$_GET['checksum'];
require 'config.php';
$get_sql = "select sample,db_max from mysql_slow_query_review_history where checksum='${checksum}' limit 1";
$result1 = mysqli_query($con,$get_sql);
list($sample_sql,$db_max_name) = mysqli_fetch_array($result1);
echo "<tr><td>" .SqlFormatter::format($sample_sql) ."</tr></td>";
?>
</table>
<div class="card-header bg-light">
执行计划:
</div>
<table class="table table-hover">
<th>id</th>
<th>select_type</th>
<th>table</th>
<th>type</th>
<th>possible_keys</th>
<th>key</th>
<th>key_len</th>
<th>ref</th>
<th>rows</th>
<th>Extra</th>
</tr>
<?php
$get_db_ip="select ip,dbname,user,pwd,port from dbinfo where dbname='${db_max_name}'";
$result2 = mysqli_query($con,$get_db_ip);
list($ip,$dbname,$user,$pwd,$port) = mysqli_fetch_array($result2);
$con_explain = mysqli_connect("$ip","$user","$pwd","$dbname","$port") or die("数据库链接错误".mysql_error());
mysqli_query($con_explain,"set names utf8");
$get_sql_explain = "EXPLAIN $sample_sql";
$result3 = mysqli_query($con_explain,$get_sql_explain);
while($row = mysqli_fetch_array($result3)){
echo '<tr>';
echo '<td>'.$row['id'].'</td>';
echo '<td>'.$row['select_type'].'</td>';
echo '<td>'.$row['table'].'</td>';
echo '<td>'.$row['type'].'</td>';
echo '<td>'.$row['possible_keys'].'</td>';
echo '<td>'.$row['key'].'</td>';
echo '<td>'.$row['key_len'].'</td>';
echo '<td>'.$row['ref'].'</td>';
echo '<td>'.$row['rows'].'</td>';
echo '<td>'.$row['Extra'].'</td>';
echo '</tr>';
}
?>
</table>
</div>
</div>
</div>
<?php
$checksum=$_GET['checksum'];
require 'config.php';
$get_sql = "select sample,db_max from mysql_slow_query_review_history where checksum=${checksum} limit 1";
$result1 = mysqli_query($con,$get_sql);
list($sample_sql,$db_max_name) = mysqli_fetch_array($result1);
$get_db_ip="select ip,dbname,user,pwd,port from dbinfo where dbname='${db_max_name}'";
$result2 = mysqli_query($con,$get_db_ip);
list($ip,$dbname,$user,$pwd,$port) = mysqli_fetch_array($result2);
$sql_advisor_export="echo '$sample_sql'";
require 'soar_con.php';
$html_str=system("$sql_advisor_export | ./soar/soar -online-dsn='${user}:${pwd}@${ip}:${port}/${dbname}' -test-dsn='$test_user:$test_pwd@$test_ip:$test_port/$test_db' -report-type='html' -explain=true -log-output=./soar.log");
echo $html_str;
echo '<br><h3><a href="javascript:history.back(-1);">点击此处返回</a></h3></br>';
?>
</body>
</html>