0

I am in need of backing up a data base (dump) that come with create schema. What is the command line using putty (via SSH) to do this job ? I researched and thought this command but it does only the tables backup and data.

mysqldump -h HOST -u LOGIN -pSENHA --opt --routines --triggers BANCO > backup.sql
Renan Rodrigues
  • 286
  • 1
  • 4
  • 22
  • that'll dump everything necessary to recreate the `BANCO` database... what exactly is the problem? – Marc B Feb 22 '16 at 19:35
  • Well, almost, @MarcB. It omits the `create database` statements. Try `mysqldump ... --databases BANCO` instead of only giving BANCO, i.e. `mysqldump -h HOST -u LOGIN -pSENHA --opt --routines --triggers --databases BANCO > backup.sql` – PerlDuck Feb 22 '16 at 19:37
  • Need to beckup so that when running SQL generated he has the possibility of creating my schema, or may need to beckup with creat schema together with him. – Renan Rodrigues Feb 22 '16 at 19:37
  • `create db` isn't usually included in there. it's expected that a db will already exist when you load a dump into it. – Marc B Feb 22 '16 at 19:39
  • However when I do the beckup by workbench he me the option to generate code with creat schema, like to do the same thing with the command. – Renan Rodrigues Feb 22 '16 at 19:46

1 Answers1

4

Use the option --databases BANCO, i.e.

mysqldump -h HOST -u LOGIN -pSENHA --opt --routines --triggers --databases BANCO > backup.sql

This will add create database (and drop database) statements to the dump.

And in case you wonder: schema and database are synonymous in MySQL: Difference Between Schema / Database in MySQL.

Community
  • 1
  • 1
PerlDuck
  • 5,610
  • 3
  • 20
  • 39