@H_301_3@
我需要使用Perl脚本更改一些
mysql密码.以下在更改数据库条目时有效,但是当我为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;
解决方法
你错过了几个步骤.
使用PASSWORD()命令并使用’admin’而不是’root’,并添加flush priv.
我在这里为你重写了脚本:
使用PASSWORD()命令并使用’admin’而不是’root’,并添加flush priv.
我在这里为你重写了脚本:
#!/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,'MysqL' ) or die $DBI::errstr; $dbh->{AutoCommit} = 0; my $sth = $dbh->prepare("update user set password=PASSWORD('$newpass') where User='root'"); $sth->execute() or die $DBI::errstr; $dbh->do('FLUSH PRIVILEGES') or die $DBI::errstr; $sth->finish(); $dbh->commit or die $DBI::errstr;
@H_301_3@