I have mysql 8 installed on Ubuntu and when I do:
SET @test := 'test'; SELECT @test;
Then I have error:
SQL 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 @test' at line 1
Why? Should I set something special in mysql configuration?
CodePudding user response:
It looks like you're trying to use multi-query, sending more than one SQL statement in a single call to the query interface. This is not supported in most client connectors by default. Some connectors have an option to enable it.
Multi-query is not supported for prepared statements regardless of any connector options.
The use cases for multi-query are very rare exceptions. Almost certainly you don't need to use multi-query.
Instead, submit one SQL statement per call to the query interface. Your session variable @test will retain its value on subsequent calls using the same MySQL session.
