如何使用mysql事件将表备份到本地磁盘

时间:2015-10-15 06:55:19

标签: mysql

我正在尝试使用下面的mysql命令将一个数据库表备份到我的本地路径作为.sql文件,

create event backupIn_home_Directory_sqlfile on every 1 day
starts '2015-10-14 16:10:00'
do
select * into outfile 'C:\Users\username\Desktop/backupcehcking.sql' from testingDB.table_test;

但是我收到以下错误:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual    that
corresponds to your MySQL server version for the right syntax to use near 'every
 1 day starts '2015-10-15 13:10:00' do select * into outfile 'C:\Users\user' at
line 1

我做错了什么?

根据答案,我改变了命令,

mysql> alter event backupIn_home_Directory_sqlfile do select * into outfile 'C:\
Users\RAGHU_ZANCT\Documents\DBbackup_Checking\backupcehcking.sql' from testing.m
anitest;
Query OK, 0 rows affected (0.00 sec)

mysql> alter event backupIn_home_Directory_sqlfile on schedule every 1 day start
s '2015-10-15 15:28:00';

尽管我在该特定文件夹中找不到backupcehcking.sql文件。为什么呢?

1 个答案:

答案 0 :(得分:0)

我想你忘记了SCHEDULE

使用它:

create event backupIn_home_Directory_sqlfile on schedule every 1 day

语法示例:

CREATE EVENT event_name
   ON SCHEDULE
     EVERY 1 DAY
   COMMENT 'Optinal comment goes here'
   DO
     YOUR QUERY;