Home » PHP » Create / Export MySQL Database backup using PHP

Create / Export MySQL Database backup using PHP

How can you create a MySQL Database backup using PHP.If you think the database is too large as GB how do you get a fastest backup?In this post will describes how to create a MySQL Database backup/dump quickly instead of using phpmyadmin access using PHP.Also you can save your time to get backup.

Following function will creating/export your database.Only you have to call to this function with passing database parameters.

Now you have to call to above function to create a backup file.

That’s only.

[stextbox id=”info”]Additional[/stextbox]
  • How to create backup file as gz format?

  • Put the following script with replacing line 77,78,79.

  • How to create backup for specific table?

  • Simply pass the table names to the function as follows.

  • How to create backup for more than one tables?

  • Pass the table names as string.

This method I tested more than ten times using 2GB large MySQL database file.If you want to get database backup daily you can put this file in to the cpanel as CRON job.

Download Create/Export MySQL Database backup using PHP Example(2 KB)


Similar posts

  • ketan

    now where is restore?

    • Backup file is store in the same location of this executing php file.

  • Anastacio Robin

    hello this is working for me but how can I put the downloaded sql file in Documents folder??? 🙂

    • Hi,
      Downloaded sql file is store in the same location of the php file.
      I’ll explain how to create any number of size db backup file in few minutes using linux command+php in the next post.


  • suraj

    excellent work

  • Gilbert Hanz

    Why? it’s can’t backup all tables?

    • call to the function with parameter $tables = ‘*’.
      this is getting all tables.


      • ikiriyo riyoki

        Hi, I tried your codeigniter chat example. It works well but I’m having a problem. I can’t store and read messages when I try to enter chat on it. Do you know what’s the main problem of it? And btw, is it easy to attached an image in chat?

        • Hi,
          check the chat.js for correct path there entered. views>chat.php for correct db details.

          • ikiriyo riyoki

            Thanks, I found already the error. It because my application has a permission. Now it works well, got another problem for now. Chat we’re working already but when I closed the chat box and reopened again, it doesn’t show the history of the chat.

          • ikiriyo riyoki

            I mean when I refresh the browser, the history will not be displayed.

  • Hari

    how to restore/import a database