免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1478 | 回复: 3
打印 上一主题 下一主题

DBI取值问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-11-19 18:06 |只看该作者 |倒序浏览
本帖最后由 zhlong8 于 2012-11-19 22:22 编辑

我使用程序想取
  1. mysql> show global status;  
  2. +------------------------------------------+--------------+
  3. | Variable_name                            | Value        |
  4. +------------------------------------------+--------------+
  5. | Aborted_clients                          | 19           |
  6. | Aborted_connects                         | 3            |
  7. | Binlog_cache_disk_use                    | 0            |
  8. | Binlog_cache_use                         | 4            |
  9. | Binlog_stmt_cache_disk_use               | 29           |
  10. | Binlog_stmt_cache_use                    | 614410       |
  11. | Bytes_received                           | 6737567730   |
复制代码
我的目标是:Aborted_clients 与Aborted_connects 的值
之后我让它们相加,输出
程序如下
#!/usr/bin/perl
#use strict;
#use warnings;
use DBI;

my $dsn="DBI:mysql:mysql:localhost";
my $username="root";
my $password="11111";
my %conn_attrs=(RaiseError=> 1, PrintError => 1, AutoCommit =>1);


my $dbh=DBI->connect($dsn,$username,$password,\%conn_attrs);
#my $sth=$dbh->prepare("select user,host,password from user;");
my $sth=$dbh->prepare("show global status");
$sth->execute();
while(my @arr=$sth->fetchrow_array()){
           print "Variable_name:$arr[0]\n";
           print "Value:$arr[1]\n";
           #print "user2:$arr->{password}\n\n";
}

$sth->finish();
$dbh->disconnect();

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
2 [报告]
发表于 2012-11-20 06:53 |只看该作者
数据库敏感操作,注意权限。
  1. GRANT SUPER, PROCESS ON *.* TO 'root'@'localhost' IDENTIFIED BY "11111";
复制代码

论坛徽章:
0
3 [报告]
发表于 2012-11-20 12:04 |只看该作者
感谢你的回复,我的数据库不能连接外网的,所以不用担心这个问题
回复 2# py


   

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
4 [报告]
发表于 2012-11-20 12:47 |只看该作者
Netwrom 发表于 2012-11-20 12:04
感谢你的回复,我的数据库不能连接外网的,所以不用担心这个问题


。。。。。。我是在说你的问题。
你的代码是可以取得你想要的值的,如果无法读出这些值,就是数据库权限问题。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP