If you have shell access to your database server, you can backup the database using mysqldump. By default, the output of the command will dump the contents of the database in SQL statements to your console. This output can then be piped or redirected to any location you want. If you plan to backup your database, you can pipe the output to a sql file, which will contain the SQL statements to recreate and populate the database tables when you wish to restore your database.
Code:
mysqldump -u [username] -p [password] [databasename] > [backupfile.sql]
o [username] - this is your database username
o [password] - this is the password for your database
o [databasename] - the name of your database
o [backupfile.sql] - the file to which the backup should be written.
To backup your database 'example' with the username 'admin' and password 'password' to a file example.sql, issue the command:
Code:
$ mysqldump -u admin -p password example > example.sql
If you'd like restrict the backup to only certain tables of your database, you
can also specify the tables you want to backup.
Code:
mysqldump -u [username] -p [password] [databasename] [table1 table2 ....]
o [tables] - This is a list of tables to backup. Each table is separated by a space
If you want to backup only table_1 & table_2 from the 'example' database,
Code:
mysqldump --add-drop-table -u admin -p password example table_1 table_2 > example.sql
You can easily restore the mysqldump file by using the mysql command. This method is usually used to recreate or rebuild the database from scratch.
Code:
mysql -u [username] -p [password] [database_to_restore] < [backupfile]
Here's how you would restore your example.sql file to the 'example' database.
Code:
mysql -u admin -p password example < example.sql
You can use AutoMySQLBackup Script that can take periodic database backups.
See: http://www.debianhelp.co.uk/mysqlscript.htm
Hope this helps.
Bookmarks