0

Right now, I'm develop a site using WAMP with the PhpMyAdmin and I'm wondering if it's possible to create a schedule event that will export couple of tables (or even all of the database) as a csv file to the server?

The purpose is to back it up to my PC with backup PC-program that will use the ftp.

What I've got so far is

DELIMITER $$

CREATE 
    EVENT `archive_blogs` 
    ON SCHEDULE EVERY 1 DAY STARTS '2017-01-13 03:00:00' 
    DO BEGIN

    SELECT * FROM orders
    INTO OUTFILE '/tmp/orders.csv'
    FIELDS TERMINATED BY ','
    ENCLOSED BY '"'
    LINES TERMINATED BY '\n'

    END */$$

DELIMITER ;

But it gives error (I tried it on the PhpMyAdmin).

Is there a better way to do that? Is there a way to do that to all of the tables in one shot?

Thanks!

iamdave
  • 10,786
  • 3
  • 20
  • 48
Dvir Naim
  • 149
  • 1
  • 8

1 Answers1

0

Run it as a cron job (at jobs in case of windows) from your PC. Try following command which is taken from other SO answer at https://stackoverflow.com/a/12843017/1012809

mysql your_db -h localhost -u root -pPasswd < query.txt | tr '\t' ','

Contents of query.txt

SELECT * FROM orders;

Even better, give a try to mysqldump command. Use the tools specifically built for tasks.

Community
  • 1
  • 1
Uday Sawant
  • 5,371
  • 3
  • 30
  • 42