Php 通过自定义artisan cammand laravel进行sql DB备份
我正在使用自定义生成的Php 通过自定义artisan cammand laravel进行sql DB备份,php,mysql,laravel,laravel-artisan,Php,Mysql,Laravel,Laravel Artisan,我正在使用自定义生成的artisan命令进行MySQLDB备份,该命令成功运行,并且还创建了一个备份文件,没有任何错误异常,但该文件为空 class BackupDatabase extends Command { protected $signature = 'db:backup'; protected $description = 'Backup the database'; protected $process; public function __con
artisan命令进行MySQL
DB备份
,该命令成功运行,并且还创建了一个备份
文件,没有任何错误异常
,但该文件为空
class BackupDatabase extends Command
{
protected $signature = 'db:backup';
protected $description = 'Backup the database';
protected $process;
public function __construct()
{
parent::__construct();
$today = \today()->format('Y-m-d');
if (!\is_dir(\storage_path('backups'))) {
\mkdir(\storage_path('backups'));
}
$this->process = new Process(sprintf(
'mysqldump -u%s -p%s %s > %s',
config('database.connections.mysql.username'),
config('database.connections.mysql.password'),
config('database.connections.mysql.database'),
storage_path("backups/{$today}.sql")
));
}
public function handle()
{
try {
$this->process->run();
$this->info('The backup has been proceed successfully.');
} catch (ProcessFailedException $exception) {
$this->error('The backup process has been failed.', $exception);
}
}
}
如果复制命令中生成的字符串并手动运行,则导出的文件是否仍然为空?是的,当尝试手动获取空文件时,则不是Laravel命令导致问题。您的MySQL命令就是问题所在。使用您正在使用的凭据通过命令行登录数据库,然后选择您正在使用的数据库。如果您看到数据,那么它可能只是权限。请提供生成的命令字符串。am使用this
php artisan db:backup
和m使用XAMPP mysql