为什么我不能在mysql中创建事件

时间:2015-10-14 09:21:34

标签: mysql

我正在尝试使用以下代码为我的某个数据库创建事件

use testing;

show events;

show warnings;

set global event_scheduler =on;

DELIMITER $$

create event table_backup_testingTo_test on schedule every 1 day 
starts '2015-10-14 16:40:00'
do
select * into test.event_table_testing from testing.manitest;

DELIMITER $$

运行此代码后,如果我签入显示活动,则 table_backup_testingTo_test

名称中没有任何事件

我在哪里做错了?

注意:我使用的是mysql workbench 6.3

2 个答案:

答案 0 :(得分:0)

您更改了分隔符,但实际上从未使用它完成语句。在多个语句之后,您应该将分隔符更改回默认值。在您的情况下,您根本不需要分隔符,因为它只是一个语句。试试这样:

DELIMITER ; /*assuming it's still set to $$*/
use testing;

show events;

show warnings;

set global event_scheduler =on;
create event table_backup_testingTo_test on schedule every 1 day 
starts '2015-10-14 16:40:00'
do
select * into test.event_table_testing from testing.manitest;

或者,如果您的活动中有多个陈述:

use testing;

show events;

show warnings;

set global event_scheduler =on;

DELIMITER $$

create event table_backup_testingTo_test on schedule every 1 day 
starts '2015-10-14 16:40:00'
do
begin
select * into test.event_table_testing from testing.manitest;
select 'we have multiple statements here';
end $$

DELIMITER ;

答案 1 :(得分:0)

我的测试:

mysql> CREATE DATABASE `testing`;
Query OK, 1 row affected (0.00 sec)

mysql> USE `testing`;
Database changed

mysql> CREATE TABLE `manitest` (
    ->   `column_0` int,
    ->   `column_1` varchar(7),
    ->   `column_2` varchar(55)
    -> );

mysql> INSERT INTO `manitest`
    -> (`column_0`, `column_1`, `column_2`)
    -> VALUES
    -> (1, 'value_1_0', 'value_2_0'),
    -> (2, 'value_1_1', 'value_2_1'),
    -> (3, 'value_1_2', 'value_2_2');
Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> CREATE DATABASE `test`;
Query OK, 1 row affected (0.00 sec)

mysql> USE `test`;
Database changed

mysql> CREATE TABLE `event_table_testing` (
    ->   `column_0` int,
    ->   `column_1` varchar(7),
    ->   `column_2` varchar(55)
    -> );
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT * INTO `test`.`event_table_testing`
    -> FROM `testing`.`manitest`;
ERROR 1327 (42000): Undeclared variable: test

mysql> INSERT INTO `test`.`event_table_testing`
    -> SELECT * FROM `testing`.`manitest`;
Query OK, 3 rows affected (0.00 sec)

mysql> CREATE EVENT `table_backup_testingTo_test` ON SCHEDULE EVERY 1 DAY
    -> STARTS '2015-10-14 16:40:00'
    -> DO
    -> -- select * into test.event_table_testing from testing.manitest;
    -> INSERT INTO `test`.`event_table_testing`
    -> SELECT * FROM `testing`.`manitest`;
Query OK, 0 rows affected (0.00 sec)

mysql> SHOW EVENTS\G
*************************** 1. row ***************************
                  Db: test
                Name: table_backup_testingTo_test
                .
                .
                .
1 row in set (0.00 sec)