mysqldump

Updated: 04 December 2024

Backup a single table

mysqldump -u the_user -h localhost -pThePassWord db_name_here table_name_here > table_name.sql

Backup data only. No CREATE DATABASE statements. No CREATE TABLE statements

mysqldump --no-create-db --no-create-info db_name > db_name.sql

mysqldump and socks tunnel

Updated: 22 May 2023

The following bash script will open a socks tunnel ti a remote host and use mysqldump locally to backup a mysql database.

#!/bin/sh
DT=$(date '+%Y-%m-%dT%H:%M:%S')
SUFFIX=
FILENAME=$DT$SUFFIX
BACKUPSPATH=
USER=
IP=
PORT=
DBUSER=
DBPASS=
DBNAME=
echo "Opening socks tunnel to $IP"
echo "Writing $FILENAME"
ssh -f -L $PORT:127.0.0.1:$PORT $USER@$IP sleep 10; \
mysqldump -u $DBUSER -h 127.0.0.1 -p$DBPASS -P $PORT --routines $DBNAME > $BACKUPSPATH/$FILENAME