Mysql backup database command line

Mysql backup database command line

Blog Bustle 16/02/2020

Mysqldump tool is used to take backup of databases in mysql. We can take all databases backup or single database backup from command line. It is fast process to take backup.

Let's know how can we take backup of mysql database in .sql format

Mysql backup database command line syntax

Mysql backup of single database

mysqldump -u [username] -p[password] [database_name] > [dump_file_name.sql];

For example, we are going to take backup of student database

Step 1: go to mysql folder directory.

Step 2: then go to bin directory inside mysql.

Step 3: write command "mysqldump -u root -p student > d:\db1.sql"

Step 4: Enter password

here username is root, password is empty, student is database and we saved backup by db1.sql in d drive of computer

mysql backup database command line

So these were the steps of mysql backup database command line.

After running this mysql backup database command line, we can import db1.sql file into any database.

If we want to save only database structure not data then mysql backup database command line will be:

mysqldump -u [username] -p[password] --no-data [database_name] > [dump_file_name.sql];

If we want to save only data not data structure then mysql backup database command line will be:

mysqldump -u [username] -p[password] --no-create-info [database_name] > [dump_file_name.sql];

Mysql backup all databases command

mysqldump -u [username] -p[password] --all-databases > [dump_file_name.sql];

After running this mysql backup database command line, saved sql file includes create database and use database statement.

If we want to take backup of some databases then mysql backup database command line will be:

mysqldump -u [username] -p[password] --databases db1 db2 db3 > [dump_file_name.sql];

After running this mysql backup database command line, saved sql file also includes create database and use database statement. Here db1, db2 and db3 are mysql databases.

If we want to take backup of some tables inside database then mysql backup database command line will be:

mysqldump -u [username] -p[password] database_name tb1 tb2 tb3 > [dump_file_name.sql];

After running this mysql backup database command line, we can import saved sql file into any database.Here tb1, tb2 and tb3 are mysql tables.

Other important links

Import database in mysql

Mysql create database

Select database in mysql

Delete database in mysql

Mysql backup database command line searches:

Tags: #mysql