I need to import few tables from MySQL to MSSQL. Below are the steps I followed in SSIS
1). Open the SQL Server Import/Export Wizard.
2). Source connections defined as per the MySQL ODBC Connector.
3). Destination defined as per MSSQL SQL authentication.
now when i try to run the package, i get the following error
"you have an error in your sql syntax; check the manual that corresponds right syntax"
On digging deep into the issue, i found that it is trying to fetch items using a query
Select * from "table"
How do i avoid double quotes? I know it is something to do with ANSI_QUOTES, but how do I set ANSI_QUOTES property
In the file ProgramData\MySQL\MySQL Server 5.6\my.ini edit the "sql-mode" property.
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,ANSI_QUOTES"
^
Related
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
I have a SSIS package which is used to export data from a MySQL database to a SQL database.
For some reason, I can only read data using the ODBC Source item but I cannot preview the table, also, while doing some other tests I found out I can't insert data with the ODBC Destination item either.
Whenever I try I get this error:
ERROR [42000] [MySQL][ODBC 8.0(w) Driver][mysqld-5.7.23]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 "TABLENAME"
at line 1 (myodbc8w.dll).
I'm using MySQL 5.7.23 and MySQL Connector/ODBC 8.0. I have tried switching between ANSI and Unicode connectors; downgrading the connectors version (tried it with 5.3, 5.2 and 5.1); changing database, table and column codification; changing the data access mode in the ODBC Source item (was using "Table Name" by default); remaking the task. Everything results in the same error, even on different computers and databases.
EDIT:
Using #Hadi second workaround lead to some interesting results (the first one didn't work for me).
Using either the ADO.NET or ODBC connector, the provided query resulted in an error.
Error Code: 1231. Variable 'sql_mode' can't be set to the value of 'NO_AUTO_CREATE_USER'
After modifying the query to
set sql_mode = 'STRICT_TRANS_TABLES, NO_ENGINE_SUBSTITUTION, ANSI_QUOTES'
the error changed to a warning.
set sql_mode='STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,ANSI_QUOTES' 0 row(s) affected, 1 warning(s): 3135 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
Still, it worked partially. Any quotations, accents, or any other symbol surrounding any selected table name had to be removed. That made it work fine when inserting data, but when retrieving data it had to be done either from a SQL command or by creating 2 different connections.
While searching for the issue i found some helpful links that mentioned some workaround:
(1) Connecting to MySQL issue
Connecting to MySQL from SSIS
In this link the author mentioned 2 methods to connect to MySQL (using ODBC and ADO.net). He mentioned that while trying to retrieve tables using ODBC he received the same error that you have listed in the question, and he mentioned the solution as below:
Switching to use a SQL query instead, and that worked just fine. I was able to pull back both the correct metadata, with one small problem - the varchar(50) columns came back with a length of 51. This resulted in some warnings, but the package ran correctly.
(2) Writing to MySQL issue
Writing to a MySQL database from SSIS
In this article the author mentioned how to write to a MySQL destination using ADO.Net destination, he mentioned the solution below:
For the ADO.NET Destination to work properly, the MySQL database needs to have the ANSI_QUOTES SQL_MODE option enabled. This option can be enabled globally, or for a particular session. To enable it for a single session:
Create an ADO.NET Connection Manager which uses the ODBC driver
Set the connection manager’s RetainSameConnection property to True
Add an Execute SQL Task before your data flow to set the SQL_MODE – Ex. set sql_mode='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,ANSI_QUOTES'
Make sure that your Execute SQL Task and your ADO.NET Destination are using the same connection manager.
Other similar links
SSIS problems with MySQL Connector/ODBC 5.3.8
SSIS and MySQL - Table Name Delimiter Issue
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.
I am trying to load data's from MySQL tables to SQL server 2012 tables.
For that i installed "mysql-connector-odbc-5.3.4-win32" driver.
After that importing data using data source " .Net Framework Data Provider For Odbc"
I gave correct connection-string and DSN for Mysql .
At last am getting an error
- Setting Source Connection (Error)
Messages
Error 0xc02020ff: Source - r_cluster [1]: The Source - r_cluster was unable to retrieve column information for the SQL command. The following error occurred: ERROR [42000] [MySQL][ODBC 5.3(a) Driver][mysqld-5.5.25]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 '"r_cluster"' at line 1
(SQL Server Import and Export Wizard)
Pipeline component has returned HRESULT error code 0xC02020FF from a method call. (Microsoft.SqlServer.DTSPipelineWrap)
Please help me to resolve this issue.
Thanks
I have just looked for the solution to this problem for myself and found the following to work.
In your ODBC Settings (make sure you are using the ANSI driver
Select the details button
In Initial statement at the bottom of the
screen set session sql_mode=ansi_quotes;
MSDN Social - MS server connect to MySQL (ODBC)
I want to import several .sql files into database using source command (mysql command line). But when I get this error:
source E:\Progs\Backups\DBs\file01.sql
ERROR:
Unknown command '\P'.
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 'sourc
e E:\Progs' at line 1
....
I used source command to import large files hundreds times but now I can not understand what I'm doing wrong. This is my system(I'm using XAMPP (Basis Package) version 1.7.3 :
Windows 7x64
MySQL 5.1.41 (Community Server) with PBXT engine 1.0.09-rc
Any help would be appreciated.
Thanks!
Edit:
I tried this one, but same error:
source 'E:\Progs\Backups\DBs\file01.sql'
MySQL sees the \P in E:\Progs as a command. Because that command does not exist, it complains.
Forward slashes are understood in many cases. Try:
source E:/Progs/Backups/DBs/file01.sql