如何写一些与mysql简单交互的perl语句?谢谢

如何写一些与mysql简单交互的perl语句?谢谢

现在需要写类似这样的代码
$ ./mysql -uroot -ppwd
mysql> create user 'web20'@'%' identified by 'web20';
mysql> grant all on *.* to 'web20'@'%' identified by 'web20' with grant option;

我如何用perl来完成呢
`./mysql -uroot -ppwd `;  可以进入mysql>
但` mysql -e 'create user 'web20'@'%' identified by 'web20' `;  没执行。

我需要怎么写呢?拜谢,比较急,希望大家帮忙 :)


[Copy to clipboard] [ - ]
CODE:
use DBI;

my $dbh = DBI->connect("DBI:mysql:testdb","root","123456",{'RaiseError' => 1});  
$dbh->do("*****************");  #操作数据库

$dbh->disconnect;

perldoc DBI
我有一篇博客文章是写使用perl操做mysql语句的。占击这里。
谢谢楼上的几位,帮了我大忙 :)
现在DBI DBD都装好了,但还是有点疑问,希望能帮忙,谢谢
./mysql -uroot -proot
mysql> create user 'web20'@'%' identified by 'web20';
mysql> grant all on *.* to 'web20'@'%' identified by 'web20' with grant option;

用DBI这么写呢?

use DBI;

my $dbh = DBI->connect("DBI:mysql:testdb","root","root",{'RaiseError' => 1}); //这里的testdb已经写成什么?? 
$dbh->do("create user 'web20'@'%' identified by 'web20';");  #操作数据库

$dbh->do("grant all on *.* to 'web20'@'%' identified by 'web20' with grant option;");

$dbh->disconnect;


谢谢大家
发现这样写是可以的
use DBI;

my $dbh = DBI->connect("DBI:mysql:","root","root",{'RaiseError' => 1}); 
$dbh->do("create user 'web20'@'%' identified by 'web20';");
$dbh->do("grant all on *.* to 'web20'@'%' identified by 'web20' with grant option;");
$dbh->disconnect;
但是提示说

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 '%' identified by 'web20'' at line 1 at /software/conf_mysql.pl line 15.


需要转义么?不知道怎么写,大家帮忙,谢谢
没人知道么。。。。
谢谢大家了
@ 前加个\, 试试
ok,这个可以啦 拜谢 :)
还有一个问题,
$dbh->do("create database web20load;");这样的语句执行第一次时候是没问题的,第二次执行脚本就要提示错误了,我怎么写才可以即使出错了也还能继续执行下去呢??

谢谢