我需要使用Perl脚本更改几个mysql密码。在更改数据库条目时以下方法可行,但当我为mysql用户更改修改时,会将它重置为空密码。在它的末尾“刷新特权”也很好,但我还没有找到该方法。如何使用Perl更改mysql密码
#!/usr/bin/perl
use DBI;
use strict;
my $newpass = "newpass";
my $driver = "mysql";
my $database = "mysql";
my $dsn = "DBI:$driver:database=$database";
my $dbh = DBI->connect($dsn, 'root', 'mysql') or die $DBI::errstr;
my $sth = $dbh->prepare("update user set password='$newpass' where User='admin'");
$sth->execute() or die $DBI::errstr;
$sth->finish();
$dbh->{AutoCommit} = 0;
$dbh->commit or die $DBI::errstr;
您正在使用哪个版本的MySQL? – titanofold