Backup MySQL database from MySQLDump File Command Line Linux

To backup your MySQL database from mysqldump file, Simply type the MySQL command mysqldump -u [username] –p[password] [database_name] > [dump_file.sql] on the Linux Ubuntu command line and press enter, and it will take database backup and store dump file into your specified location.

How to Take Backup of MySQL database from mysqlDump File in Linux Ubuntu Command Line

Here are some steps to take backup of MySQL database using mysqldump file via terminal on Linux Ubuntu Server:

Step 1: Log in to your MySQL server

To login into the MySQL server, Simply type mysql -u root -p command on the command line or prompt, and press enter:

mysql -u root -p

Step 2: Select the database

After login to MySQL server, you need to select db which you want to backup, for this, you can use use my_database; command on command line:

use my_database;

Replace ‘my_database‘ with the name you want to give your database.

Step 3: Backup a MySQL Database Using mysqldump via Command Line

To backup MySQL database using mysqldump, Just type the mysqldump -u [username] –p[password] [database_name] > [dump_file.sql] on Linux Ubuntu command line, which you can use like this:

mysqldump -u [username] –p[password] [database_name] > [dump_file.sql]

Where:

  1. mysqldump: Command-line utility in MySQL used for exporting databases or specific tables.
  2. -u [username]: Specifies the MySQL user for authentication.
  3. –p[password]: Indicates the password for the specified user. There should be no space between -p and the password.
  4. [database_name]: Specifies the name of the MySQL database to be dumped.
  5. > [dump_file.sql]: Redirects the output of the mysqldump command to a file named dump_file.sql. This file will contain the SQL statements necessary to recreate the specified database.

Compress Backup of MySQL Database in Linux Command Line

If the size of MySQL db is more than 3GB, you will need to backup the db by compressing it, you can use mysqldump database_name -u database_username -p | gzip > database_backup_name.sql.gz command on the linux ubuntu command prompt:

mysqldump database_name -u  database_username -p | gzip > database_backup_name.sql.gz

Multiple MySQL Database Backup using mysqldump in Linux Command Line

To backup multiple or all MySQL databases at once, Just type mysqldump mysqldump –databases mydb1 mydb2 > backup.sql on the command line and press enter, this will backup all your MySQL databases in one file:

mysqldump --databases mydb1 mydb2 > backup.sql

Step 4: Verify the restore

Open a terminal and use the cd command to navigate to the directory where the MySQL database backup file is located.

cd /path/to/backup/directory

Use the ls command to list the files in the directory and verify the presence of the MySQL database backup file.

ls

Here is the video guide on how to take backup of mysql database using mysqldump command in linux command prompt:

Conclusion

With the help of the tutorial, you learned how to take backup of MySQL database using mysqldump file via the command line or terminal on linux ubuntu server.

Recommended Tutorials

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *