getting error when creating EVENT in MySQL - mysql

When i'm trying to create an EVENT in my MySQL getting this error
Script line: 1 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
'EVENT `e_hourly`
ON SCHEDULE
EVERY 1 HOUR
COMMENT 'Clears out s' at line 1
I'm attaching my create EVENT code here
CREATE EVENT `e_hourly`
ON SCHEDULE
EVERY 1 HOUR
COMMENT 'Clears out sessions table each hour.'
DO call testing();#here i'm trying to call a stored proc

Your Event Code seems to be fine, perhaps you don't have support for events in your mysql version?
We usually format events as:
DELIMITER $$
DROP EVENT IF EXISTS E_Hourly$$
CREATE EVENT E_Hourly ON SCHEDULE EVERY 1 HOUR COMMENT 'Clears out sessions table each hour' DO
EV:BEGIN
CALL Testing();
END$$
DELIMITER ;
SET GLOBAL event_scheduler = ON;

Related

Error with MySQL syntax in event sql-script. Delimeter already used

I have this script for update table monthly:
DELIMITER |
CREATE
EVENT `kpiparams_scheduled_update`
ON SCHEDULE
EVERY 1 MONTH
STARTS '2020-02-01 02:59:59'
ON COMPLETION PRESERVE
COMMENT 'KPIParams was updated by event_kpiparams_scheduled_update'
DO
BEGIN
UPDATE kpiparams INNER JOIN kpiparams_update
ON kpiparams.param_name = kpiparams_update.param_name
SET kpiparams.good = kpiparams_update.good,
kpiparams.bad = kpiparams_update.bad,
kpiparams.weight_gold = kpiparams_update.weight_gold,
kpiparams.weight_tech = kpiparams_update.weight_tech,
kpiparams.is_for_calc = kpiparams_update.is_for_calc
WHERE kpiparams.param_name = kpiparams_update.param_name;
END |
DELIMITER ;
This code drop exception:
Caused by: java.sql.SQLSyntaxErrorException: 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 'DELIMITER | CREATE EVENT kpiparams_scheduled_update ON SCHEDULE EVERY 1 MONTH ST' at line 1
And this:
nested exception is java.sql.SQLSyntaxErrorException: 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 'DELIMITER | CREATE EVENT kpiparams_scheduled_update ON SCHEDULE EVERY 1 MONTH ' at line 1
I serched some resources that said, I need use Delimeter, don't write amount of months in '' and use BEGIN-END. By the way, it didn't help me.
spring.datasource.schema=classpath*:mysql-scripts/event_update_kpiparams.sql
EDITED SCRIPT:
CREATE
EVENT kpiparams_scheduled_update
ON SCHEDULE EVERY 1 MONTH STARTS '2020-02-01 02:59:59'
ON COMPLETION PRESERVE
COMMENT 'KPIParams was updated by event_kpiparams_scheduled_update'
DO
BEGIN
UPDATE kpiparams INNER JOIN kpiparams_update
ON kpiparams.param_name = kpiparams_update.param_name
SET kpiparams.good = kpiparams_update.good,
kpiparams.bad = kpiparams_update.bad,
kpiparams.weight_gold = kpiparams_update.weight_gold,
kpiparams.weight_tech = kpiparams_update.weight_tech,
kpiparams.is_for_calc = kpiparams_update.is_for_calc
WHERE kpiparams.param_name = kpiparams_update.param_name;
END
I guess you tried to run this using JDBC?
You don't need DELIMITER | at all. That's a mysql client builtin command. Client builtins are not recognized by the SQL parser.
You can just execute the CREATE EVENT statement as a single statement and then you don't need to have a delimiter at the end of the statement. Delimiters are only important in interfaces that support multiple statements (e.g. the mysql client).
Okay it seems you are using multiple statements in an .sql file and you need some way of separating the statements. Normally this is ; but you have some statements that contain ; as part of the statement, not as the separator.
I'm not a Spring developer, but I found Spring Boot Database initialization MySQLException for Trigger which describes the use of:
spring.datasource.separator
This is also documented: https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html
spring.datasource.separator
(default) ;
Statement separator in SQL initialization scripts.

MYSQL Create Event

I am trying to expand my knowledge with MYsql and every time I run this via workbench, I get an syntax error but I can not seem to find it. I have been looking all over google for help with this and I did copy 2 tutorials to get to this stage.
DELIMITER $$
CREATE EVENT[IF NOT EXIST]`warning_reset`
ON SCHEDULE EVERY 1 WEEK
STARTS '2017-03-06 18:00:00'
ON COMPLETION PRESERVE
DO BEGIN
call warning_script;
END */$$
DELIMITER ;
Error Below:
Error Code: 1064. You have an error in your SQL syntax; check the
manual that corresponds to your MariaDB server version for the right
syntax to use near '*/' at line 7
The event creation syntax is, to put it politely, gnarly.
Here's a rewrite of your code that works.
DELIMITER $$
CREATE EVENT `warning_reset`
ON SCHEDULE EVERY 1 WEEK
STARTS '2017-03-06 18:00:00'
ON COMPLETION PRESERVE
DO BEGIN
call something_or_other;
END $$
DELIMITER ;
It's best to drop and recreate events rather than use IF NOT EXISTS. If you do use IF NOT EXISTS don't use square brackets.
For some reason you had */ in your code. That's a close-comment tag. I took it out.

When Creating Trigger I got Error #1064 in Mysql 5

Error:
#1064 - 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 '' at line 6
My Trigger
CREATE TRIGGER `register_notification_after_register`
`AFTER INSERT ON register FOR EACH ROW BEGIN
Set #notification = CONCAT('New Member Register. Membership Code is',' ',new.membership_no,'.');
Set #notificationfor =CONCAT('New Membership');
call notification_masterAddUpdate(1,#notification,#notificationfor,new.reg_date,1);
END
try this:
DELIMITER $$
CREATE TRIGGER `register_notification_after_register`
AFTER INSERT ON register FOR EACH ROW BEGIN
Set #notification = CONCAT('New Member Register. Membership Code is',' ',new.membership_no,'.');
Set #notificationfor =CONCAT('New Membership');
call notification_masterAddUpdate(1,#notification,#notificationfor,new.reg_date,1);
END
$$ -- I am done server, end of block
DELIMITER ;
you had an extra backtick on line two. One needs to set the DELIMITER to block the whole thing. With create event, create stored proc, create trigger, delimiters clue the server into when the whole chunk is done. Remember that the ; ends a statement. The delimiter statement suspends that in favor of something else, then resets at end of block

MySQL Error:1064 while calling a stored procedure from an event

CREATE EVENT E_UpdateTimestampFields
ON SCHEDULE
EVERY 1 MINUTE
STARTS TIMESTAMP(CURRENT_DATE,'00:00:00')
ON COMPLETION PRESERVE
DO `ndwnaleveringen`
CALL spc_UpdateTimeStampFields();
This is the code for creating the event which will call a stored procedure spc_UpdateTimeStampFields(). ndwnaleveringen is the name of the database.
While executing this event I am getting the error
Error Code: 1064
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 'CALL spc_UpdateTimeStampFields()' at line 7
Try
CREATE EVENT E_UpdateTimestampFields
ON SCHEDULE
EVERY 1 MINUTE
STARTS TIMESTAMP(CURRENT_DATE,'00:00:00')
ON COMPLETION PRESERVE
DO
CALL ndwnaleveringen.spc_UpdateTimeStampFields();

MySQL CREATE TRIGGER and DELIMITER ISSUES

I am trying to make a database that does some inventory checking, and I am working on some triggers to update everything as required. In this case, that I want to do is to take the current availability (disponibilidad) of an ingredient from the ingredients table, add to it how much is taken or added, and then save that value into the table stock_disponibilidad, as you can see from the trigger code I am trying to use.
DELIMITER $$
CREATE TRIGGER `update_disponibilidad_variacion` BEFORE INSERT ON `stock_disponibilidad`
FOR EACH ROW BEGIN
DECLARE old_disp DOUBLE DEFAULT 0;
SELECT disponibilidad INTO old_disp FROM ingredientes WHERE id = NEW.ingredientes_id;
NEW.disponibilidad = old_disp + NEW.variacion;
END$$
DELIMITER ;
However, whenever I execute the query to create the trigger, I get the following error:
#1064 - 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 '.disponibilidad = old_disp + NEW.variacion; END' at line 5
I've done everything I read about this issue, still without result. What am I doing wrong?