mysql查询在perl中不起作用

时间:2021-11-09 11:59:01

I am beginner for perl developer. i am connecting mysql by perl script . but when i try hit some queries. all queries are running successfully except one. and where i use that query on mysql console it runs successfully.

我是perl开发人员的初学者。我通过perl脚本连接mysql。但当我尝试点击一些查询。所有查询都成功运行,除了一个。我在mysql控制台上使用该查询,它运行成功。

#!/usr/bin/perl -w

use DBI;

$dbh1 = DBI->connect('dbi:mysql:testing;host=localhost', 'root', '93C0o35A9/692fz') or die "Connection Error: $DBI::errstr\n";

$dbh1->do('stop slave');
$dbh1->do('CHANGE MASTER TO MASTER_HOST=54.254.154.33, MASTER_USER=replica, MASTER_PASSWORD=aims145, MASTER_LOG_FILE=mysql-bin99, MASTER_LOG_POS=107');
$dbh1->do('start slave');

first and third queries are running fine while second one is showing syntax error as follows

第一个和第三个查询正常运行,而第二个查询显示语法错误,如下所示

 ./newmysql.pl

DBD::mysql::db do failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '54.183.14.179, MASTER_USER=replica, MASTER_PASSWORD=aims145, MASTER_LOG_FILE=mys' at line 1 at ./newmysql.pl line 8.

DBD :: mysql :: db失败:您的SQL语法有错误;查看与您的MySQL服务器版本相对应的手册,以便在./newmysql.pl第8行的第1行附近的'54 .183.14.179,MASTER_USER = replica,MASTER_PASSWORD = targets145,MASTER_LOG_FILE = mys'附近使用正确的语法。

mysql查询在perl中不起作用 Please help me here where i am wrong.

我在这里错了,请帮帮我。

3 个解决方案

#1


1  

The documentation recommends to quote the values of the different variables, try:

文档建议引用不同变量的值,尝试:

$dbh1->do("CHANGE MASTER TO MASTER_HOST='54.254.154.33', MASTER_USER='replica', MASTER_PASSWORD='aims145', MASTER_LOG_FILE='mysql-bin99', MASTER_LOG_POS=107");

#2


0  

I am not confident that administrative commands like that can work through DBI (and I can't test it at present) nor do I think you should be doing things that way, but I think the problem may be that the parameters to the command aren't quoted properly.

我不相信像这样的管理命令可以通过DBI工作(我目前无法测试它),也不认为你应该这样做,但我认为问题可能是命令的参数不是引用得当。

I suggest you change the command to this. At least it will make it more readable

我建议你把命令改成这个。至少它会使它更具可读性

$dbh1->do(<<'__END_SQL__');
CHANGE MASTER TO
  MASTER_HOST     = '54.254.154.33',
  MASTER_USER     = 'replica',
  MASTER_PASSWORD = 'aims145',
  MASTER_LOG_FILE = 'mysql-bin99',
  MASTER_LOG_POS  = 107
__END_SQL__

#3


0  

$dbh1->do("CHANGE MASTER TO MASTER_HOST=\'54.183.14.179\', MASTER_USER=\'replica\', MASTER_PASSWORD=\'aims145\', MASTER_LOG_FILE=\'$mainip[0]\', MASTER_LOG_POS=$mainip[1] ");

#1


1  

The documentation recommends to quote the values of the different variables, try:

文档建议引用不同变量的值,尝试:

$dbh1->do("CHANGE MASTER TO MASTER_HOST='54.254.154.33', MASTER_USER='replica', MASTER_PASSWORD='aims145', MASTER_LOG_FILE='mysql-bin99', MASTER_LOG_POS=107");

#2


0  

I am not confident that administrative commands like that can work through DBI (and I can't test it at present) nor do I think you should be doing things that way, but I think the problem may be that the parameters to the command aren't quoted properly.

我不相信像这样的管理命令可以通过DBI工作(我目前无法测试它),也不认为你应该这样做,但我认为问题可能是命令的参数不是引用得当。

I suggest you change the command to this. At least it will make it more readable

我建议你把命令改成这个。至少它会使它更具可读性

$dbh1->do(<<'__END_SQL__');
CHANGE MASTER TO
  MASTER_HOST     = '54.254.154.33',
  MASTER_USER     = 'replica',
  MASTER_PASSWORD = 'aims145',
  MASTER_LOG_FILE = 'mysql-bin99',
  MASTER_LOG_POS  = 107
__END_SQL__

#3


0  

$dbh1->do("CHANGE MASTER TO MASTER_HOST=\'54.183.14.179\', MASTER_USER=\'replica\', MASTER_PASSWORD=\'aims145\', MASTER_LOG_FILE=\'$mainip[0]\', MASTER_LOG_POS=$mainip[1] ");