Changes

Backup The MySQL Database

1,754 bytes added, 15:10, 1 July 2017
The following lines were added (+) and removed (-):
&nbsp;== SQL Dump ==Using mysqldump is an effective tool to backup your MySQL database. This method creates text files in sql syntax with DROP table, CREATE table and INSERT into sql-statements of the source database. To restore the database,  execute the *.sql file on the destination database.  Using mysqldump is the recommended method for using with the Innodb engine.  For databases using the MyISAM engine the use of mysqlhotcopy is faster.Note:  The mysqld service is running when you use mysqldump.=== mysqldump backup ===The most common use of mysqldump is probably for making a backup of whole databases.   mysqldump --all-databases --lock-tables -p > all_databases.sqlThis will back up all databases and prevent access during the backup process.  The --lock-tables is what prevents the database from being modified during the backup.  The -p switch will prompt you for your mysql password before commencing.  The > is to output to the file name of your choice ending in the .sql extension, for creation of a text readable file.If you wish to backup a specific table    mysqldump --opt payroll --lock-tables -p > payroll_backup.sqlIn this example we pipe the backup into gnuzip to compress it for archival purposes.  mysqldump --opt payroll --lock-tables -p | gzip > payroll_backup.sql.gzIn this example the payroll table is being dumped to a backup file.  It is possible to dump several databases with one command.  mysqldump --databases payroll accounting --lock-tables -p > business_backup.sql=== mysql restore ===To restore a single table to the database.  mysql -p payroll < payroll_backup.sqlTo restore multiple tables to the database.  mysql -p < business_backup.sql&nbsp;&nbsp;[[Category:SQL]]
Bureaucrat, administrator
14,711
edits