I am at the very beginning of mysql, trying to insert data into a new schema called crashcourse.
My code is:
use crashcourse;
source /Users/chenxinyu/Downloads/mysql_scripts/create.sql ;
source /Users/chenxinyu/Downloads/mysql_scripts/populate.sql ;
But it turns out that "11:35:24 source /Users/chenxinyu/Downloads/mysql_scripts/create.sql 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 /Users/chenxinyu/Downloads/mysql_scripts/create.sql' at line 1 0.00031 sec", so how can I solve this problem?
There are a number of commands, including source, that are only recognized by the MySQL command-line client. See https://dev.mysql.com/doc/refman/8.0/en/mysql-commands.html
These commands are parsed and handled by that client, and are not sent to the MySQL Server. This makes them different from all other SQL statements, which are sent to the server to be parsed and executed.
Other clients, such as MySQL Workbench, phpmyadmin, and other developer tools, would need to implement support for those special client-side commands themselves. Few of them do.
Likewise when you write code to use the MySQL API in your own applications, unless you pre-check the SQL statement and handle the special client-only commands yourself, they are not supported.
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 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.
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?
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 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"
^