-3

I'm new to sql and trying to get to grips with some of the basics.

Say I've created a database as follows:

create database mydatabase;

and I want to back this up to a dump file. My confusion comes in here - what is this dump file? Does this automatically generate when I run the mysqldump command? Do I have to create it beforehand? If so, how? Sorry if this comes off stupid but I'm just lost here.

I know the final command would look as follows:

mysqldump -u -p mydatabase > SOMETHING;

but I don't know what to actually insert as the something

jarlh
  • 42,561
  • 8
  • 45
  • 63
Mike
  • 11
  • 1
  • 3
  • Does this answer your question? [Copy/duplicate database without using mysqldump](https://stackoverflow.com/questions/25794/copy-duplicate-database-without-using-mysqldump) – Ashish Ratan Mar 17 '21 at 07:26
  • [MySQL 8.0 Reference Manual / ... / mysqldump — A Database Backup Program](https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html) - study. – Akina Mar 17 '21 at 07:28
  • Please share more details. What do you mean by "what is this dump file"? – Nico Haase Mar 17 '21 at 07:31
  • @Nico Haase I mean from the information I've been given I need a dump file that serves as the target of my backup... but I don't know what this actually entails - do I have to manually create this file? How do I do that? What specifically do I need to do for my backup to work? – Mike Mar 17 '21 at 07:38
  • "What specifically do I need to do for my backup to work" - that depends on your application. The file is generated by calling `mysqldump` - why not simply try and see what happens? – Nico Haase Mar 17 '21 at 08:04
  • @Nico Haase when I call mysqldump I'm given syntax errors – Mike Mar 17 '21 at 08:24
  • If you see any error messages, please share them – Nico Haase Mar 17 '21 at 08:32
  • @NicoHaase If I call >mysqldump; I get the following message: ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysqldump' at line 1 – Mike Mar 17 '21 at 09:30
  • Please add all information to your question by editing it. `mysqldump` is a seperate command, it should not be called through the MySQL shell – Nico Haase Mar 17 '21 at 10:09

1 Answers1

0

The dump file is just a file usually with a bunch of scripts you can run to recreate something in the database. Different database system have their own way of generating these, but you could effectively take a dump from an mysql database and into another rdbms as long as the scripts are compatible.

There are different options;

  1. You could create a dump of just the schema. So that you can recreate that database later on without the data.

  2. Create the dump with schema and data. So that you can recreate the scheme as well as the data within it.

  3. Create the dump with just the data. So you can run those insert commands against another database of the same schema.

Basically dumps are just a way to get back to a previous state. They come in handy for different situation. Such as backing up data, replicating a data from one database to another.

As for the commands I have not used mysql in a while but looks like you are on the right track.

Claudiga
  • 427
  • 1
  • 4
  • 15