Invalid syntax in WHILE loop for MySQL 8.0.26 - mysql

I'm running MySQL 8.0.26 inside a Linux container, using Docker.
I am attempting to run a stress test by infinitely selecting data from a table named employees in the employees database. To attempt this, I am embedding a SELECT statement inside of a WHILE loop, with a search condition that always returns true.
I am attempting to issue the following query against the MySQL engine, using the MySQL CLI tool.
WHILE 1=1 DO
SELECT * FROM employees.employees;
END WHILE;
When I run this query, I receive the error message as follows.
Error invoking remote method 'DB_EXECUTE_CANCELLABLE_QUERY': 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 'WHILE 1=1 DO SELECT * FROM employees.employees; END WHILE' at line 1
According to the MySQL documentation, I am using the correct syntax. What is wrong with this SQL statement?
Docs: MySQL Comparison Operators
Docs: MySQL WHILE Statement

The WHILE statement is only valid inside MySQL stored procedures, functions.

Related

Error when SQL query called from C program

I want to execute SOURCE data/keyw.sql from C program. This query works fine when I execute from the command line but gives the following error on executing mysql_query(con, "SOURCE data/keyw.sql")
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 'SOURCE data/keyw.sql' at line 1
Any help would be highly appreciated.
The SOURCE command is not executed on the MySQL server. It is interpreted by the mysql Client, and is basically just a convenience.
Quote from MySQL documentation:
mysql sends each SQL statement that you issue to the server to be executed. There is also a set of commands that mysql itself interprets. For a list of these commands, type help or \h at the mysql> prompt:
Note that source is one of those listed. If you want to know how it works, then have a look at the source code for the mysql Client.
If your source to be executed contains more than one MySQL statement then your connection will need to support multiple statement execution, or alternatively you need to parse the SQL into individual statements yourself.

'Syntax Error' when using Database Navigator for PyCharm

I have a project with a MySQL database to which I connected using the Database Navigator plugin.
Now when I open the DB Browser window, select the database and click on "Open DB console" and insert the query
SELECT CAST('2017-08-29' AS DATE);
for one, the IDE highlights CAST as an unknown identifier:
and, additionally, when I try to execute the statement, I get the error
Error executing SELECT 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 '' at line 1 - Connection: test: 112ms
However, to my knowledge, this is valid MySQL, at least this page suggests so.
I am also able to perform MySQL queries with casts from a python script that builds the connection itself.
What am I doing wrong here? Do I have to configure the dialect for Database Navigator?

Not able to work with mysql stored procedure in ssrs

I am not able to work with MySQL stored procedures in SSRS.
While using Mysql queries dataaset get created successfully. but if want to fetch data from stored procedures with parameter i get this error.
ERROR [42000] [MySQL][ODBC 8.0(a) Driver][mysqld-8.0.13]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 'ims_data.GetUploadStatus' at line 1
ODBC does not support named parameters. you need to use ? for parameters
You can try
CALL ims_data.GetUploadStatus(?)
or
EXEC ('CALL ims_data.GetUploadStatus(?)', #p_period) AT MySQL (Linked Server Name)

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!

Parameterize MySQL workbench statements: How to define variables

I'm trying to parameterize a set of frequently used queries in my workbench.
This works:
select * from providers where id='112233';
This
WbVarDef var1=112233;
select * from providers where id='$[var1]';
gives error
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 'from providers where id='112233'' at line 1
My reference was this.
Just to be clear, these are in the MySQL workbench and not a workbench script file or a mysql script file.
In MySQL, syntax for setting variable is below.
SET #var1 = '112233';
and using the variable would be as below.
select * from providers where id=#var1;
Check out MySQL documentation for more information Link to MySQL Documentation
Based on your tag mysql-workbench, I find it simply to be a case where the referenced documentation and use is not relevant to what you are using.
Back up the hierarchy from your link to this http://www.sql-workbench.net/
and you will read:
Please note that SQL Workbench/J has no relation to the product MySQL
Workbench which is maintained and owned by Oracle. If you
are looking for MySQL Workbench support please contact Oracle.