Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 通过自定义artisan cammand laravel进行sql DB备份_Php_Mysql_Laravel_Laravel Artisan - Fatal编程技术网

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