我能够从浏览器运行脚本并备份我的 mysql 数据库,但是当我尝试使用 cron 作业执行此操作时,出现错误:
严格的标准:在 /main_dir/sub_dir/backup.php 中只应通过引用传递变量警告:在命令行界面上使用密码可能不安全。
有什么建议?而且,为什么会出现密码警告?
<?php
//Enter your database information here and the name of the backup file
$mysqlDatabaseName ='xxxxxxxxxxxxxx';
$mysqlUserName ='xxxxxxxxxxxxxx';
$mysqlPassword ='xxxxxxxxxxxxxx_';
$mysqlHostName ='xxxxxxxxxxxxxx';
$mysqlExportPath ='xxxxxxxxxxxxxx.sql';
//Please do not change the following points
//Export of the database and output of the status
$command='mysqldump --opt -h' .$mysqlHostName .' -u' .$mysqlUserName .' -p' .$mysqlPassword .' ' .$mysqlDatabaseName .' > ' .$mysqlExportPath;
exec($command,$output=array(),$worked);
switch($worked){
case 0:
echo 'The database <b>' .$mysqlDatabaseName .'</b> was successfully stored in the following path '.getcwd().'/' .$mysqlExportPath .'</b>';
break;
case 1:
echo 'An error occurred when exporting <b>' .$mysqlDatabaseName .'</b> zu '.getcwd().'/' .$mysqlExportPath .'</b>';
break;
case 2:
echo 'An export error has occurred, please check the following information: <br/><br/><table><tr><td>MySQL Database Name:</td><td><b>' .$mysqlDatabaseName .'</b></td></tr><tr><td>MySQL User Name:</td><td><b>' .$mysqlUserName .'</b></td></tr><tr><td>MySQL Password:</td><td><b>NOTSHOWN</b></td></tr><tr><td>MySQL Host Name:</td><td><b>' .$mysqlHostName .'</b></td></tr></table>';
break;
}
?>
应该允许我使用 cron 作业进行 mysql db 备份。
明月笑刀无情