mysql: DELIMITER syntax error at line 1 - mysql

I try to add this function using the following SQL in phpmyadmin/MySQL
DROP FUNCTION IF EXISTS `__myv`;
DELIMITER ;;
CREATE FUNCTION `__myv`(`a` int, `b` int) RETURNS bigint(20)
BEGIN
return FLOOR(a / b);
END;;
DELIMITER ;
but I get this error:
Error
SQL query:
DELIMITER;
MySQL said: Documentation
#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 'DELIMITER' at line 1
How to fix this error??

DELIMITER is a Mysql console command, You can't use it in phpmyadmin.
To set the delimiter in phpmyadmin, see this other answer

Even if DELIMITER is a console command, phpMyAdmin's import module has accepted it since many years. When opening a database and clicking on SQL, a query entered there is passed to the import module, so it should work (unless you have a very old phpMyAdmin version).

Related

MySQL Workbench - Stored Procedure - Error - No reference in manual

I am using MySQL workbench 8.0.18 on a mac.
I am trying to run the following stored procedure using $$ as my delimiter. It is not running and giving me 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 '' at line 3
And here is the code with the delimiter:
delimiter $$
create procedure HelloWorld()
begin
select 'Hello World!';
end $$
I have gone through the documentation for mysql workbench but could not find any relevant answer pertaining to it.
Thank you for your help in advance.
You have to run this in a NORMAL query tab when you want to use DELIMITER:
If you want to add a procdure in new_procedure Routine
Leave out the DELIMITER completely,
When you save the procedure Workbench will add the DELIMITER abd DEFINER automatically

mysql using tee in stored procedure

I'm new to MySQL (or SQL in general)
I'm trying to get MySQL to write the timestamp into a file with stored procedure using TEE command (I don't think I can use "select into outfile" because I don't want to delete the file, I want to add a line to it...):
mysql> DELIMITER $$
mysql> CREATE PROCEDURE test_to_file()
-> begin
-> TEE /home/ubuntu/test.txt;
-> SELECT NOW();
-> end $$
However, I get an 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 '/home/ubuntu/test.txt;
SELECT NOW();
end' at line 3
Thanks for the help
Disclaimer: I am not certain that whatever you are trying to do is necessarily a good idea... but there is a simple solution for this.
Create a table using the CSV Storage Engine.
You can then append to the file by simply inserting into this table.
Using tee is a client-side feature. It doesn't write to the server at all, unless you happen to be running the mysql client on the server machine... in which case, it's only writing to the server machine by coincidence.

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/

MYSQL Wamp Server

please help me out in the following code its a syntax error but i don't understand where is the error i tried to run this trigger on Wamp server
here is the code:
CREATE TRIGGER Drivers_type_constraint BEFORE INSERT ON Cars
FOR EACH ROW
BEGIN
IF ((NEW.driver_name='null')||(NEW.driver_age<17)) THEN
DELETE from Drivers where driver_id = NEW.driver_id;
END IF;
END;
/
Error
you have an error in your SQL Syntax; Check the manual that correspond to your sql server version for the right syntax to use near '' at line 8
If anyone want to suggest any idea it would be appreciated thanks in advance.

MySQL delimiter syntax error

I'm trying to change the MySQL command delimiter so I can create a procedure with multiple commands in it. However, the delimiter command does not seem to be recognised on MySQL 5.1.47. I tested it on MySQL 5.0.91, and it did work there.
DELIMITER //;
DELIMITER ;//
I'm trying to run this from phpmyadmin, in both situations. Using 5.0.91 instead isn't an option because I need to use events (CREATE EVENT).
Error message:
#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 'DELIMITER //' at line 1
Is there a reason it's not working, or is there an alternative to accomplish the same thing (creating a procedure with multiple queries)?
DELIMITER is not a MySQL command. It's a command that your MySQL client needs to support. I was running PHPMyAdmin 2.8.2.4, which didn't support it. When I upgraded to the newest version, which is currently 3.4.9, it worked just fine. Your MySQL version has nothing to do with DELIMITER and whether it's supported or not.
You don't need to delimit the DELIMIT statements
DELIMITER //
procedure here etc
DELIMITER ;
Exactly as per "Defining Stored Programs" in the MySQL docs.
And if you can control versions, the latest is 5.5.20. Why not use that?
Edit:
The error message indicates an error in the previous statement... if this can't be seem force it thus
; /* <- force previous statement termination */ DELIMITER //
procedure here etc
DELIMITER ;