hcymysql / slowquery

Slowquery图形化显示MySQL慢日志工具
https://dbaplus.cn/news-11-2520-1.html
145 stars 58 forks source link

explain数据不展示 #4

Open kells-h opened 4 years ago

kells-h commented 4 years ago

您好,大佬explain过程中出现一下问题,麻烦帮指导下,谢谢

image 通过慢查询explain过程中出现调用dbinfo数据链接报错。 尝试手动把$con_explain = mysqli_connect(修改成数据库连接信息,不在报数据库链接失败) 但是,explain没有任何显示 image

hcymysql commented 4 years ago
    $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)){

以上的代码意思是:从dbinfo表里获取被监控主机MySQL的IP相关信息,然后与其建立会话连接。将查询的结果用函数mysqli_fetch_array取出来,存放入数组$row里,并循环打印出来。 估计是你的账号权限,不能远程访问吧?你创建一个'admin'@'%'远程账号试试?

hcymysql commented 4 years ago

您好,大佬explain过程中出现一下问题,麻烦帮指导下,谢谢

image 通过慢查询explain过程中出现调用dbinfo数据链接报错。 尝试手动把$con_explain = mysqli_connect(修改成数据库连接信息,不在报数据库链接失败) 但是,explain没有任何显示 image

$get_sql = "select sample,db_max from mysql_slow_query_review_history where checksum=${checksum} limit 1";

你看下 mysql_slow_query_review_history这个表里有数据吗?

kells-h commented 4 years ago
    $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)){

上面的代码的意思是:从dbinfo表里获取被监视主机MySQL的IP相关信息,然后建立会话连接。将查询的结果用函数mysqli_fetch_array取来,放入入$$ row里,并循环打印出来。 估计是你的账号权限,不能远程访问吧?你创建一个'admin'@'%'远程账号试试? 权限都是管理员账户。测试可以访问的 image 我使用的apache2.4.6 php5.4 mysql5.7

kells-h commented 4 years ago

您好,表中有慢sql数据的

image

hcymysql commented 4 years ago

您好,表中有慢sql数据的

image

select sample,db_max from mysql_slow_query_review_history where checksum=${checksum} limit 1 手工查询下,可以查出来吗?

kells-h commented 4 years ago

感谢答复。 问题已经找到,pt分析mysql5.7生成checksum包含数字和字母。故脚本写入到sql_db的时候无法写入。通过修改字段为varchar类型。数据写入正常。 然而也需要修改slowquery_explain.php中的'${checksum}' 加上引号

kells-h commented 4 years ago

checksum修改成了varchar类型,需要把脚本修改一下,问题解决掉了。 select sample,db_max from mysql_slow_query_review_history where checksum='${checksum}' limit 1

非常感谢大佬  

Kells-Huang

 

------------------ 原始邮件 ------------------ 发件人: "hcymysql"<notifications@github.com>; 发送时间: 2019年11月21日(星期四) 晚上6:21 收件人: "hcymysql/slowquery"<slowquery@noreply.github.com>; 抄送: "忘却折@脊"<1126649667@qq.com>; "Author"<author@noreply.github.com>; 主题: Re: [hcymysql/slowquery] explain数据不展示 (#4)

您好,表中有慢sql数据的

select sample,db_max from mysql_slow_query_review_history where checksum=${checksum} limit 1 手工查询下,可以查出来吗?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

hcymysql commented 4 years ago

checksum修改成了varchar类型,需要把脚本修改一下,问题解决掉了。 select sample,db_max from mysql_slow_query_review_history where checksum='${checksum}' limit 1 非常感谢大佬   Kells-Huang   ------------------ 原始邮件 ------------------ 发件人: "hcymysql"<notifications@github.com>; 发送时间: 2019年11月21日(星期四) 晚上6:21 收件人: "hcymysql/slowquery"<slowquery@noreply.github.com>; 抄送: "忘却折@脊"<1126649667@qq.com>; "Author"<author@noreply.github.com>; 主题: Re: [hcymysql/slowquery] explain数据不展示 (#4) 您好,表中有慢sql数据的 select sample,db_max from mysql_slow_query_review_history where checksum=${checksum} limit 1 手工查询下,可以查出来吗? — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

感谢分享。我修改下代码。