mysql dump of data only – no table and database schema

Mates, I want to dump the data from the tables only rather than its definition and data.

The problem with mysqldump is it checks if database/table exist  or not. if the table exist it drops the table create the blank table and then enters the insert into statements. I don’t want to use this.

goggled and found

dump the database with options –no-create-db and –no-create-info
Advertisements

Mysql Database Backup script

Create a file called database_backup.sh and also an empty directory called mysql_backup.

The database_backup.sh script should have the following info :

#!/bin/sh 
date=`date '+%m-%d-%y'`
PATH="~/mysql_backup/database_name.$date"
mysqldump -u database_username -pdatabase_password database_name > $PATH


Run the script that performs the backup job.

Using Cron  :

Set this script up to run every night, etc. as a cron job. It will save an sql dump of your database every night in the mysql_backup.
e.g

* 23 * * * your_userid /path/to/backup/script

Backing Up MySQL Database

MySQL database backup can be accomplished in two ways:

a) Copying the raw mysql database files &
b) Exporting tables to text files



Copying the Mysql database Files :

MySQL uses the same table format on different platforms, so it’s possible to copy MySQL table and index files from one platform and use them on another without any difficulties (assuming, of course, that you’re using the same version of MySQL on both platforms).

Exporting tables to text files.

The MySQLDump is handy utility that can be used to quickly backup the MySQL Database to the text files. To use the MySQLDump utility it is required to logon to the System running the MySQL Databse. You can use Telnet to remotely logon to the system if you don’t have the physical access to the machine.
The syntax for the command is as follows.

mysqldump -u [Username] -p [password] [databasename] > [backupfile.sql]

[username] – this is your database username
[password]- this is the password for your database
[databasename] – the name of your database
[backupfile.sql] – the filename for your database backup

Let’s discuss the example of backing up MySQL Database named “accounts” into text file accounts.sql. Here are the scenarios of taking the backup assuming that both user name and password of the database is “admin”.

a) Taking the full backup of all the tables including the data.

Use the following command to accomplish this:
mysqldump -u admin -p admin accounts > accounts.sql

b) Taking the backup of table structures only.

Use the following command to accomplish this:
mysqldump -u admin -p admin –no-data accounts > accounts.sql

c) Taking the backup data only.

Use the following command to accomplish this:
mysqldump -u admin -p admin –no-create-info accounts > accounts.sql

Restoring MySQL Database

Restoring the MySQL is very easy job. You can use the following to command to restore the accounts database from accounts.sql backup file.

mysql – u admin -p admin accounts < accounts.sql

In this tutorial you learned how to take the backup of your MySQL Database and restore the same in the event of some database crash or on some other machine.