Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL restoring a database via mysqldump - Does it overwrite the different destination tables?

I am using mysqldump to backup a database containing several tables (say tables D, E, F). I use the following command: mysqldump -uuser -ppassword SourceDatabase > file.sql to backup these tables.

I would like to know if I restored this backup, would it overwrite other tables? For example, if I have a database DestinationDatabase, containing tables A, B and C, and after running the command "mysql -uuser -ppassword DestinationDatabase < file.sql", would I lose the tables A, B and C on the destination database (and be left with just D, E and F) or would I be left with A, B, C, D, E and F (with the original tables present in DestinationDatabase left untouched)?

Thanks in advance, Tim

like image 323
TMM Avatar asked Mar 29 '11 15:03

TMM


People also ask

How to back up and restore a MySQL database?

In this tutorial, we present two easy ways to back up and restore your MySQL Database. The mysqldump client utility can dump a database including the SQL statements required to rebuild the database. By default, the dump file includes the SQL commands to restore the tables and data. To back up your MySQL database, the general syntax is:

How do I backup multiple tables using mysqldump?

To backup multiple tables using mysqldump, enter the table names separated by a space after the database name. For example, this command will backup both the author and book tables in the gravity_books database. mysqldump -u root -p gravity_books author book > db_gravity_author_book.sql The SQL file generated contains the commands for both tables.

How to restore an SQL dump file in MySQL?

Restoring an SQL dump file using the SOURCE command. To restore the mydb.sql SQL dump file, you follow these steps: First, connect to MySQL server: C:>mysql -u root -p Enter password: ********. Second, drop the mydb database: mysql> drop database mydb; Third, use the SOURCE command to load the dump file: mysql>source c: backup mydb.sql.

What is mysqldump in MySQL?

The mysqldump utility is a command-line tool that comes with the MySQL databaseand lets you backup and restore your database. It produces SQL files that can be used to restore the database. You can use it to backup one or more databases, or backup tables within a database.


1 Answers

With the default options, it will not delete tables A, B and C. It will however overwrite (delete current data that is not in the backup) tables D, E and F.

To see the list of available options see here.

like image 55
The Scrum Meister Avatar answered Oct 13 '22 09:10

The Scrum Meister