0
0
MySQLquery~5 mins

mysqldump usage

Choose your learning style9 modes available
Introduction
mysqldump helps you save a copy of your database so you can keep it safe or move it somewhere else.
You want to back up your database before making big changes.
You need to move your database to a new server or computer.
You want to share your database with someone else.
You want to save your data before upgrading MySQL.
You want to create a copy of your database for testing.
Syntax
MySQL
mysqldump -u [username] -p [database_name] > [filename].sql
Replace [username] with your MySQL username.
Replace [database_name] with the name of your database.
The > symbol saves the output to a file named [filename].sql.
Examples
Backs up the 'mydatabase' database using the 'root' user and saves it to 'backup.sql'.
MySQL
mysqldump -u root -p mydatabase > backup.sql
Backs up the 'sales_db' database using user 'user123' and saves it to 'sales_backup.sql'.
MySQL
mysqldump -u user123 -p sales_db > sales_backup.sql
Backs up all databases on the server and saves them to 'all_databases.sql'.
MySQL
mysqldump -u root -p --all-databases > all_databases.sql
Sample Program
This command will ask for the root user's password, then save the 'testdb' database to 'testdb_backup.sql'.
MySQL
mysqldump -u root -p testdb > testdb_backup.sql
OutputSuccess
Important Notes
You will be prompted to enter your password after running the command.
The backup file is a text file containing SQL commands to recreate the database.
Make sure you have permission to write the backup file in the folder you run the command.
Summary
mysqldump creates a backup of your MySQL database as a SQL file.
Use it before big changes or to move your database.
You run it from the command line with your username and database name.