2

How can we backup MySQL database using Query, like we can backup MS-SQL using following Query.

Query:

backup database DATABASENAME to disk = 'PATH'

2 Answers 2

2

Use mysqldump-php a pure-PHP solution to replicate the function of the mysqldump

 <?php
    require('database_connection.php');
    require('mysql-dump.php')
    $dumpSettings = array(
        'include-tables' => array('table1', 'table2'),
        'exclude-tables' => array('table3', 'table4'),
        'compress' => CompressMethod::GZIP, /* CompressMethod::[GZIP, BZIP2, NONE] */
        'no-data' => false,            
        'add-drop-table' => false,      
        'single-transaction' => true,   
        'lock-tables' => false,        
        'add-locks' => true,            
        'extended-insert' => true      
    );

    $dump = new MySQLDump('database','database_user','database_pass','localhost', $dumpSettings);
    $dump->start('forum_dump.sql.gz');
        ?>

also visit this link GitHub

Sign up to request clarification or add additional context in comments.

Comments

2

Check out the documentation for mysqldump

The mysqldump client utility performs logical backups, producing a set of SQL statements that can be executed to reproduce the original database object definitions and table data.

It dumps one or more MySQL databases for backup or transfer to another SQL server. The mysqldump command can also generate output in CSV, other delimited text, or XML format.

As noted by Havenard it is already installed with MySQL Server and MariaDB, and is considered the official way of backing up a database.

1 Comment

Additional note: mysqldump is already installed with MySQL Server, it is the official way of backing up databases and requires you to install nothing else.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.