How to define DB functions in MySQL Docker? - mysql

When using a SQL file placed inside /docker-entrypoint-initdb.d/ defining functions fails with the following error:
ERROR 1064 (42000) at line 6: 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 3
This is the content of the SQL file:
CREATE DATABASE alpha;
USE alpha;
SET GLOBAL log_bin_trust_function_creators = 1;
create function addit(a int, b int) returns int
begin
return a+b;
end
The above code works perfectly well when I connect to the instance after creation and run it.
Is it not allowed to define functions in db init scripts? How do I get around this?

Related

How to resize mysql> innodb_temp_data_file_path = ibtmp1:12M:autoextend:max:5G;? Using Mysql 8.0

I tried to resize in many different ways but I always get the same error:
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 'innodb_temp_data_file_path=ibtmp1:12M:autoextend:max:500M' at line 1
As mysql manual on sysvar_innodb_temp_data_file_path says, it is not a dynamic variable, therefore cannot be set using set sysvar_innodb_temp_data_file_path=... method via sql. You need to include it either in your mysql config file or as a startup parameter to the mysql service.

creating stored procedure in ubuntu terminal

I am trying to create stored procedures in mysql. I am doing it on terminal (ubunutu).
But when I am adding ; before end it executes all lines and throw an error .
I am trying to write
create procedure test()
-> begin
-> select * from salary;
I am unable to add end in last and it executeds and got this error
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 '' at line 3.
Is this a right way to write stored procedure in terminal ?
Can I write stored procedure on separate file?
Then how can I execute that stored procedure written in file ?
fortunately i found a way to write a stored procedures on terminal
http://alextsilverstein.com/programming-and-development/mysql/mysql-the-reason-for-using-the-delimiter-statement-in-mysql-routines-stored-procedures-functions-triggers/

Is there a way to run multi-SQLs by RMySQL(dbExecute)?

I am using RMySQL to connect and manipulate MySQL.
Now I have a SQL like:
"drop table if exists t_tmp; create table t_tmp(name varchar(20));"
which works just fine in MySQL CLI.
But when I put these SQLs to RMySQL.dbExecute() exception throws:
"could not run statement: 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 'create table t_tmp(name varchar(20))' at line 1"
I am trying to run the 2 SQLs respectively, then they both work out OK.
Is there any way I can put the whole STRING(SQLs) and run it correctly in RMySQL?
Thanks!

I did error check on DataGrip but the sql file was still generating a syntax error when I try to run it

So I was installing a schema on my MySql database. I error checked the sql script on DataGrip, it shows no syntax error; yet when I runt it the syntax error pop up
ERROR 1064 (42000) at line 54: 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 '.ortholog_seq_a_ix on orthomcl.ortholog(sequence_id_a)' at line 1
The original code is as follow:
CREATE TABLE orthomcl.Ortholog (
SEQUENCE_ID_A VARCHAR(15),
SEQUENCE_ID_B VARCHAR(15),
TAXON_ID_A VARCHAR(15),
TAXON_ID_B VARCHAR(15),
UNNORMALIZED_SCORE DOUBLE,
NORMALIZED_SCORE DOUBLE
);
CREATE INDEX orthomcl.ortholog_seq_a_ix on orthomcl.ortholog(sequence_id_a);
By the way I'm using an ubuntu system.
CREATE INDEX ortholog_seq_a_ix on orthomcl.ortholog(sequence_id_a);
Does it work? May be you don't need to specify schema in index definition if it's already specified in table def

Can't find out what's wrong with this MySQL event syntax

I'm trying to create a MySQL event, and this is the syntax I'm using:
CREATE EVENT test
ON SCHEDULE AT FROM_UNIXTIME(1428005286)
DO
BEGIN
UPDATE blog_posts SET status = 'published' WHERE id = 5;
END
When I run it on Node.js (with the mySQL adapter, under Sails.js), I get no error, but the event doesn't get created. When I run it directly through phpMyAdmin, I get:
#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 5
I have also tried adding a semicolon to END, making it END;, and removing all semicolons, and it returns a slightly similar 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 'END' at line 6
I have no idea why this is happening. Any help is appreciated. Thanks.
You probably need to start with: create DEFINER=root#localhost ...
Also, since this is a one-liner, you don't need BEGIN..END