Jump to content

[SOLVED] Command Line Database Table Backup


Recommended Posts

Hi, I'm having a little trouble.

 

I'm moving a 280Mb database to a new server which consists of about 36 tables. As you can imagine phpMyadmin is having trouble with the export and import. I have found command line ways to backup the whole database but I was wondering if there is a way to backup individual tables and then import the individual tables via SSH?

 

Many thanks

Here is an excerpt from a  bash script that I used to use for backing up my entire server

backup.sh

#!/usr/bin/env bash
function backup_sql() {
    dbs=`mysql -u root --batch -e "SHOW DATABASES;"`
    backup_dir=/backups/mysql/
    for db in $dbs; do
if [ "$db" != "Database" ]; then
	mysqldump --opt -c -e -Q -q --single-transaction -u root $db > $backup_dir/$db.sql
fi
    done
}
if type "$1" | grep -qF "$1 is a function"; then "$@"; fi

 

Usage: backup.sh backup_sql

 

If you only want to backup one db just do something like this

mysqldump --opt -c -e -Q -q --single-transaction -u root YOUR_DB > /path/to/YOUR_DB.sql

 

I now use LVM snapshots for backing up/migrating my mysql server.

Thats great thank you but I'm trying to backup a specific table out of the database?

 

Many thanks

 

Yeah just add the table name after the db.

 

Like this:

 

mysqldump --opt -c -e -Q -q --single-transaction -u root YOUR_DB YOUR_TABLE > /path/to/YOUR_TABLE.sql

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.