@ryan.murray
To backup a MySQL database in Laravel, you can use the mysqldump
command-line tool or the BackupManager
package. Here's how you can do it using mysqldump
:
- Open your terminal or command prompt and navigate to your Laravel project directory.
- Run the following command to perform a backup using mysqldump:
mysqldump -u [username] -p [database_name] > [backup_file_name.sql]
Replace [username] with your MySQL username, [database_name] with the name of the database you want to backup, and [backup_file_name.sql] with the desired filename and location for the backup file. Note that you'll be prompted to enter your MySQL password after running the command.
- The backup file will be stored in the location you specified.
Alternatively, you can use the BackupManager
package to automate the backup process. Here are the steps:
- Install the package using Composer:
composer require spatie/laravel-backup
- Publish the package's configuration file by running the following command:
php artisan vendor:publish --provider="SpatieBackupBackupServiceProvider"
- Open the config/backup.php file and configure your backup settings, such as specifying the disk where the backup files should be stored.
- Run the backup command using Artisan:
php artisan backup:run
This command will perform the backup according to the settings in the configuration file.
- The backup file will be stored in the specified disk location.
Remember to schedule regular backups using Laravel's task scheduler to automate the backup process.