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

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!

Related

Error code: 1064 in MySQL when create SOURCE?

I want to use my SQL'book_data2' file from the desktop E drive as a 'SOURCE'. But I am getting an error code 1064 in MySQL workbench. Could you help me for that issue? I am giving the code and action output below.
Code:
SOURCE E:\DataPractice\Practice\book_data2.sql;
Action Output:
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 'SOURCE E:\DataPractice\Practice\book_data2.sql' at
line 1 0.000 sec
There are a number of commands that are supported by the mysql client (that is, the command-line client, not MySQL Workbench), but they are parsed in the client, not sent to the server as SQL statements. The MySQL Server does not recognize these commands.
It can be confusing, but remember both the client and the server may process commands. You just have to read the documentation to learn which commands are in the list of client-only commands:
https://dev.mysql.com/doc/refman/8.0/en/mysql-commands.html
(Except USE, which is recognized by both mysql client and server, just to make sure there's an exception to every rule!)
If you want to use MySQL Workbench to "source" an SQL file, in other words load a file, read the SQL commands in that file, and execute them, Workbench does support this action, but they call it Data Import/Restore. It's documented here: https://dev.mysql.com/doc/workbench/en/wb-admin-export-import-management.html

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.

setting the target database version for mysql workbench migration

I am running a migration from sql server to mariadb 10.0 and the generated code keeps failing due to a syntax error in the create table statements.
Specifcally it doesn't like the INDEX lines of the create table statements. And example of a statement it chokes on is
CREATE TABLE t1 (
`fk_manager` varchar(255),
INDEX `imgr` (`fk_manager` ASC) visible
);
This is the error I get
ERROR 1064 (42000): 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 'INDEX
`imgr` (`fk_manager` ASC) visible)'
at line 3
If i remove the visible keyword the same command works, so I assume this is syntax valid on newer versions of mysql but not mine. Is there any way I can tell mysql workbench to exclude it?
In the top menu click Model > Model Options
In the dialogue that pops up, select MySQL on the left side
Change Target MySQL Version to 5.7

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)

How to restore dump file using Mysql Query Browser

When i am trying to run some queries from the batch file i am getting some error message in my query browser
I have tried with
source E:\Rename_scripts_unused_tables_msp.sql
and i am getting error message like
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 E:\Rename_scripts_unused_tables_msp updated.sql' at line 1'
And the query works fine in command line.
Here is my source file statements:
rename table appliance_backup_usage_history to unused_appliance_backup_usage_history;
rename table backup_core_server to unused_backup_core_server;
rename table bdr_vms to unused_bdr_vms;
rename table client_details1 to unused_client_details1;
rename table client_service_technologies_backup to unused_client_service_technologies_backup;
rename table cloud_instances to unused_cloud_instances;
and more statements like that
What's the reason behind this ??
source is a mysql CLI command - not an SQL query command. It only works using the command line client mysql.
https://dev.mysql.com/doc/refman/5.7/en/mysql-batch-commands.html