Simple transaction query but has syntax error - mysql

I am trying some sammple query in mysql client but the transaction syntax does not work]
MySQL database-2:3306 ssl TestDb SQL > START TRANSACTION
-> select * from mvcc where glyph = 'a'
-> COMMIT
-> ;
And it reports syntax 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 'select * from mvcc where glyph = 'a'
COMMIT' at line 2
This seems to be a very simple query and it's too easy to understand why it fails. I can run the select statement without any issue. Any idea?

You need a semicolon at the end of each of the queries.
START TRANSACTION;
SELECT * FROM mvcc WHERE glyph = 'a';
COMMIT;

Related

MySQL 8.0 not being able to create any query plans

I have a very simple query:
explain
select *
from mytable
limit 1
And I cannot see the execution plan, I receive this 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 'explain select * from mytable limit 1' at line 1
Why doesn't this work?

Error Code: 1064 - You have an error in your SQL syntax

I have a very strange problem with this code:
Update creature_template SET health_min=(health_min * 0.03) where entry in (select entry from creature where rank ='1');
Update creature_template SET health_max=(health_max * 0.03) where entry in (select entry from creature where rank ='1');
Error occured at:2021-01-07 13:27:46
Line no.:1
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 '='1')' at line 1
I use mysql 8.x and I am a beginner. in mysql 5.x this problem does not exist.
Anyone if can help i would be grateful.
rank is a reserved word in MySQL since version 8.0.2. You need to escape it with backticks
... where `rank` = '1' ...

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

i got an error while im trying to execute query views in mysql version 5.7.19
Here is my query :
CREATE ALGORITHM=UNDEFINED DEFINER=`acc_webdev`#`%` SQL SECURITY DEFINER VIEW `view_dash_total` AS
SELECT
COUNT(0) AS `jumlah`,
SYSDATE() AS `tanggal`
FROM `table_laporan`
WHERE (STR_TO_DATE(`table_laporan`.`dt_added`,'%d-%m-%Y') < (SYSDATE() + INTERVAL - (1)DAY))$$
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 6
but in mysql 5.1.25, there's no error when i execute the query above
please help me out
Either prepend your DDL with DELIMITER $$ or just change your delimiter to ;.
Read more about delimiters here
Try This:
CREATE VIEW `view_dash_total` AS
SELECT
COUNT(0) AS `jumlah`,
SYSDATE() AS `tanggal`
FROM `table_laporan`
WHERE (STR_TO_DATE(`table_laporan`.`dt_added`,'%d-%m-%Y') < (SYSDATE() + INTERVAL - (1)DAY));

Syntax error when trying to run an IF EXISTS query

I am trying to run the below query (in Sequel Pro), but I am getting the following syntax error:
'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 'IF
(EXISTS(SELECT username FROM USER WHERE username = "TestObserver"))
{SELECT *' at line 1'
Code:
IF EXISTS (SELECT username FROM USER WHERE username = "TestObserver")
SELECT * FROM USER WHERE username = "TestObserver"
You can't use an if block outside of a function. Instead just run the subsequent SQL statement:
SELECT * FROM `USER` WHERE username = "TestObserver"
If there is no username with testobserver value it will already return nothing all by itself.

Mysql Select Last inserted row

I'm creating a stored procedure using phpmyadmin for mysql 5.5.55 .
INSERT INTO drama_ (value1,value2,value3,value4,value5,value6)
VALUES (val1,val2,0,0,0,0);
SELECT LAST_INSERT_ID();
but i'm getting a syntax error in SELECT LAST_INSERT_ID();
EDIT :
You have an error your SQL syntax: check the manual that corresponds to your MYSQL server version for the right syntax to use near 'SELECT LAST_INSERT_ID()' at line 4