The Blog

Uncategorized

Persistent connect to additional MySQL in a clever way.

Posted on


# create ssh key
ssh-keygen

# copy ssh key to the mysql source server
ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected] -p 2222

# use this to test ssh connection
ssh [email protected] -p 2222

# here we make persistent connection to the source DB by changing DB port
ssh -fNg -L 3307:127.0.0.1:3306 [email protected] -p 2222

# and here we make the connection!
mysql -h 127.0.0.1 -P 3307 -u root -p some_db_on_source_server

Posted in Uncategorized Leave a comment

Backup and Restore compressed MySQL databases using gz or bz2

Posted on

Backup

mysqldump --routines -u root -p --databases db1 db2 db3 | gzip > /var/www/backups/mysql/databases.sql.gz # multiple db using gzip
mysqldump --routines -u root -p --databases db1 db2 db3 | bzip2 > /var/www/backups/mysql/databases.sql.bz2 # multiple db using bz2

mysqldump --routines -u root -p db1 | gzip > /var/www/backups/mysql/db1.sql.bz2 # single db using gzip
mysqldump --routines -u root -p db1 | bzip2 > /var/www/backups/mysql/db1.sql.bz2 # single db using bz2

Restore

bunzip2 < db1.sql.bz2 | mysql -u root -p db1
zcat db1.sql.gz | mysql -u root -p db1

Same goes for multiple DBs just add one or more DB to restore at the end of the command, or leave blank to restore all.

Posted in Uncategorized Leave a comment
« Previous PageNext Page »