mysql_mysqldump_database
This is an old revision of the document!
Basic Dump
You can then perform a dump with:
1 |
mysqldump -u root -p database > filename.sql |
Recommended:
You can also use the following to add date to the mysql dump:
1 |
mysqldump database > mysql_dump_name_backup.$( date + "%Y-%m-%d" ).sql |
Dumping with progress report
1 |
mysqldump database | pv > mysql_dump_name_backup.$( date + "%Y-%m-%d" ).sql |
Note: It may be benefitial to run the mysql dump in a screen session depending on how large the database is.
To view database size please visit: https://lukeslinux.co.uk/mysql_database_sizes
Importing
Once you have created the db you can import with:
1 |
mysql -u root -p mytestdb2 < mytestdb.sql |
Advanced mysql dump
Database Engine
Check the db engines before you dump. This will allow you to find the most efficient way of dumping the tables
Replace “database name” with the name of your database
1 |
mysql -e 'SELECT TABLE_NAME, ENGINE FROM information_schema.TABLES where TABLE_SCHEMA = "database name" |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
+------------------------+--------+ | TABLE_NAME | ENGINE | +------------------------+--------+ | wp_commentmeta | MyISAM | | wp_comments | MyISAM | | wp_links | MyISAM | | wp_options | MyISAM | | wp_popularpostsdata | InnoDB | | wp_popularpostssummary | InnoDB | | wp_postmeta | MyISAM | | wp_posts | MyISAM | | wp_term_relationships | MyISAM | | wp_term_taxonomy | MyISAM | | wp_terms | MyISAM | | wp_usermeta | MyISAM | | wp_users | MyISAM | +------------------------+--------+ |
Creating A DUMP
You will need to dump the db based on the storage engine:
INNODB
source: http://dev.mysql.com/doc/refman/5.6/en/mysqldump.html#option_mysqldump_single-transaction
1 |
mysqldump -u user -p --single-transaction mydatabase > /my/backup/directory/mydatabase_date .$( date + "%Y-%m-%d" ).sql |
1 |
mysqldump -u user -p --single-transaction mydatabase | pv > /my/backup/directory/mydatabase_date .$( date + "%Y-%m-%d" ).sql |
myISAM
source: http://dev.mysql.com/doc/refman/5.6/en/mysqldump.html#option_mysqldump_lock-tables
1 |
mysqldump -u user -p --lock-tables mydatabase > /my/backup/directory/mydatabase_date .$( date + "%Y-%m-%d" ).sql |
1 |
mysqldump -u user -p --lock-tables mydatabase | pv > /my/backup/directory/mydatabase_date .$( date + "%Y-%m-%d" ).sql |
HYBRID
–lock-all-tables will provide a consistent backup for hybrid databases
1 |
mysqldump -u user -p --lock-tables mydatabase > /my/backup/directory/mydatabase_date .$( date + "%Y-%m-%d" ).sql |
1 |
mysqldump -u user -p --lock-tables mydatabase | pv > /my/backup/directory/mydatabase_date .$( date + "%Y-%m-%d" ).sql |
mysql_mysqldump_database.1450095895.txt.gz · Last modified: 2024/05/23 07:26 (external edit)