Backup & Restore

Backup & Restore

Esempi pratici di backup e ripristino dati di un database mysql. Come utilizzare un DUMP dei dati.

Creare un dump dei dati

Per creare una copia dei dati presenti in un determinato database, è sufficiente utilizzare il comando mysqldump, come nel seguente esempio:

mysqldump -u username -p password nome_database > dump.sql


Questo creerà un file chiamato dump.sql che contiene la copia di tutti i dati del database selezionato.

Se invece si desidera salvare i dati di tutti i database presenti, il comando sarà il seguente:

mysqldump -u username -p password --all-databases > dump.sql


Un'ulteriore richiesta potrebbe essere di creare una copia di backup di una sola tabella, ecco come fare:

mysqldump -u username -p password nome_database nome_tabella > dump.sql

Caricare il dump del database

Questa volta viene chiamato in causa il client mysql, a cui, come sempre, passiamo i parametri username e password, oltre al nome del file DUMP da caricare.

mysql [-h nome_host] -u username -p [password] nome_database < dump.sql


Un'ulteriore metodo per caricare il file di backup è utilizzare la sintassi mysql --execute, che, come descritto in un altro articolo, esegue un comando (in questo caso source) ed effettua immediatamente la disconnessione.

mysql [-h nome_host] -u username -p [password] nome_database --execute "source dump.sql"

Publication details

Category: MySQL

Published by: loryzz on date: 06.01.2008 20:51:50

Last edit by: loryzz on date: 21.01.2009 11:34:11

Statistics

Details  This article has been viewed 3.347 times.

Send to

add to digg add to reddit add to furl add to facebook add to delicious add to google add to stumbleupon add to technorati add to ask add to live

Ratings

  • Currently 0; ?>/ TOTALSTARS
  • 1
  • 2
  • 3
  • 4
  • 5

Comments

Details 0 user comments, 0 still waiting.

Leave a comment

All comments must be approved by site administrator.
Please write comments on topic. Spam will be never approved.


Confirmation code

Please take a look to image and insert character into the form field.