Why are these comments in a mysql file blowing up? - mysql

On the Linux command line I call this script via the mysql terminal using source...
--First insert new template types
insert into TemplateType(id,name,size)
values (10,'Feature Sheet','8.5x11 ss');
insert into TemplateType(id,name,size)
values (11,'Feature Sheet','8.5x11 ds');
insert into TemplateType(id,name,size)
values (12,'Feature Sheet','11x17');
When I do I get an error saying my sql syntax is invalid. Is this not the correct way to comment an sql file?

Apparently you need whitespace after the -- or use a # instead....
http://dev.mysql.com/doc/refman/5.0/en/comments.html

Related

JMeter sql syntax error using parameters with insert

I'm working with JMeter to load test queries on a mySQL database (memsql server, mySQL syntax). I'm using a gui version of JMeter to create a test plan xml file and then go to another server and run that xml in non-gui mode.
I have two queries running, one that selects and one that inserts. Both queries use parameters taken from a csv file I made with a script.
My SELECT statement works just fine with parameters taken from a csv file but I run into syntax errors with my INSERT statement:
INSERT INTO customer_transactions_current (`column_name1`, ... , `column_name12`)
VALUES ((${r1},${r2},${r3},${r4},${r5},${r6},${r7},${r8},${r9},${r10},${r11},${r12}));
In the section of the query in the gui mode under 'CSV Data Set Config' I choose to delimit the data by ',' and the variable names are r1,..,r12.
Under the query itself I entered the parameter types and again the same names, just as I did for the working SELECT query.
When I run the query I run into a syntax error on the first column (which is of type datetime):
java.sql.SQLSyntaxErrorException: 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 '19:00:00,75400492,936988,56,1115,5,2156,8,2,3,909,3))' at line 2
The dates I'm entering are of the form: '2018-11-2 20:00:00' and in the csv file they are present without apostrophes.
It seems that the syntax error has something to do with the date and in the position where it holds a space. I tried entering the STR_TO_DATE function for that column but kept getting syntax errors.
BUT when I try to take some values from the file and manually run the query it works fine! So my thoughts are that it has something to do JMeter's conversion of spaces before sending out the query.
Is the problem with my configurations of JMeter? Since the query is OK manually.
Add apostrophes to insert and remove unnecessary parenthesis
INSERT INTO customer_transactions_current ('column_name1', ... , 'column_name12')
VALUES ('${r1}','${r2}','${r3}','${r4}','${r5}','${r6}','${r7}','${r8}','${r9}','${r10}','${r11}','${r12}');
If you have date issue see using STR_TO_DATE

restore mysql backup file using php

I can get backup file for mysql database using php and every thing gone nice , but when I trying to restore this backup file I have mysqli 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 'INSERT INTO radpostauth VALUES ('289','ah','ah','Access-Accept','2017-08-14 10:' at line 7
in other hand when I take the query which is writed into the file and past it in php my admin directly it executed without any error I am sure that the query is right
I have 3 empty line between every insert query when I run the file the first insert query is executed but the error is show when want to execute the second insert query
INSERT INTO radcheck VALUES ('1229','ah','Cleartext-Password',':=','ah','','','','','','','','');
INSERT INTO radpostauth VALUES ('289','ah','ah','Access-Accept','2017-08-14 10:04:22'), ('290','muh','asdfghjkl','Access-Accept','2017-08-14 10:05:30'), ('291','sda','sad','Access-Accept','2017-08-14 11:21:48'), ('292','sda','sad','Access-Accept','2017-08-14 11:55:40'), ('293','sda','sad','Access-Accept','2017-08-14 11:59:03'), ('294','sda','sad','Access-Accept','2017-08-14 12:52:58'), ('295','sda','sad','Access-Accept','2017-08-14 13:41:41'), ('296','sda','sad','Access-Accept','2017-08-14 14:50:40'), ('297','sda','sad','Access-Accept','2017-08-15 09:45:40'), ('298','ah','ah','Access-Accept','2017-08-16 12:52:09'), ('299','ah','ah','Access-Accept','2017-08-17 09:19:53');
why I have this wrong
Try using mysqli::multi_query() instead of mysqli::query(). It allows the execution of multiple queries at once.

SQL Server to Mysql migration (using Mysql Workbench). How to add data with manually escaped apostrophe during steps in Workbench wizard?

I know how to escape apostrophe. The question is different. How to add data with manually escaped apostrophe during steps in Workbench wizard?
I have the same question as in
SQL Server to Mysql migration (using Mysql Workbench) data transfer error
How can I manually add escape to apostrophe (') and then run the last step in workbench wizard for DATA MIGRATION?
My error is different:
Statement execution failed: 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 's Homestead','Regina Murphy','Sales Representative','707 Oxford Rd.','Ann Arbor'' at line 1:
INSERT INTO `Northwind`.`Suppliers` (`SupplierID`, `CompanyName`, `ContactName`, `ContactTitle`, `Address`, `City`, `Region`, `PostalCode`, `Country`, `Phone`, `Fax`, `HomePage`)
VALUES
(3,'Grandma Kelly's Homestead','Regina Murphy','Sales Representative','707 Oxford Rd.','Ann Arbor','MI','48104','USA','(313) 555-5735','(313) 555-3349',NULL),
It looks like apostrophe in word "Kelly's" produce the problem.
I'm working on the same issue. As far as I can tell you need to run
Replace(string_column, '''', '''''');
or
Replace(string_column, '''', '&apos');
on the source DB before import. It might be possible to run it as part of the import script, I'm not sure. My scripting abilities are somewhat limited.
Edit:
This worked for me on a MSSQL Server:
BEGIN TRANSACTION;
UPDATE [dbo].[Table]
SET Field = REPLACE(Field, '''', '''''');
COMMIT TRANSACTION;
It is Milosz Bodzek's answer.
I only reformulated it.
It looks like the only existing option is to copy database -> make changes in this database (escape strings) -> perform migration with workbench wizard.
It is a bug in MySQL Workbench(version 6.3.8). Here's the bug page: http://bugs.mysql.com/bug.php?id=83616
Edit:
As it turns out, when migrating with Migration Wizard in Workbench, if string in the source column(could be text or varchar) has apostrophe character in it, you get that error because Workbench does not escape the apostrophe.
I have encountered the same issue and used Topplestack's workaround. I also replaced apostrophe back in MySQL after migration in order to avoid changing source data.
Edit 2:
They have fixed it in MySQL Workbech 6.3.9. This is entry is from bug fixes part of the changelog:
Having a single quotation mark (') in the text field of a table caused the MySQL Schema Transfer wizard to fail. (Bug #24978403, Bug #83616)

SQL syntax checker in phpMyAdmin rejects good code?

I'm using the SQL window in phpMyAdmin (3.5.7) to insert rows into a MySql table, but am having problems with the syntax checker. It's running on Windows Server 2003.
If I click the "INSERT" button to generate a template, then overtype the values in the template, there is no problem. However I because I need to populate a large number of rows I have auto-generated INSERT statements using Excel, pasted them into a text editor, and then pasted them into the same phpMyAdmin SQL window. The results are baffling...
The statement below (generated using Excel/text editor/copy&paste) gives an error:
#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 ''timeslot' ('slot_no', 'slot_starttime') VALUES (3,'00:30')' at
line 1
INSERT INTO 'timeslot' ('slot_no', 'slot_starttime') VALUES (2,'00:15')
The statement below is fine however (it was constructed by clicking the INSERT button on the SQL window then over-typing the text in the template:
INSERT INTO `timeslot`(`slot_no`, `slot_starttime`) VALUES (2,'00:15')
I have copied and pasted both statements into this post directly from the phpMyAdmin window. They look pretty much the same to me, so I can't understand why the first one fails.
???
If you have pasted the results directly as you say, there is a syntax error.
In MYSQL you cannot enclose field or table names using the apostrophe sign. Rather you've got to use the BACK-QUOTE (on the tilde key)
So the following is WRONG:
INSERT INTO 'timeslot' ('slot_no', 'slot_starttime') VALUES (2,'00:15')
And the folowing is CORRECT:
INSERT INTO `timeslot` (`slot_no`, `slot_starttime`) VALUES (2,'00:15')
And even the following is CORRECT (without the back-quotes):
INSERT INTO timeslot (slot_no, slot_starttime) VALUES (2,'00:15')
The common single quote (') is used only for VALUES in an SQL statement.

not able to insert the data into a table in a database via a text file

i am new to the databases and i recently downloaded mysql 5.1 and learning the commands from a website. i am not able to insert the data from a file into a database. i am using the command line and typed the same command from
http://www.webdevelopersnotes.com/tutorials/sql/mysql_course_inserting_data_in_mysql_tables.php3
but it was issuing an error.. i am using windows 7.. is the file format not supported ? or the command is wrong? please help... thanks in advance
the file name is "nit.dat"... created the database named 'nitish' and a table inside it named 'stud' now i typed
mysql nitish < nit.dat ;
at the command line... and i kept the file nit.dat in the bin directory.... the file contains three records to be inserted.....
insert into stud ( id, name, age ) values ( 99, "nit", 23);
insert into stud ( id, name, age ) values (22, "nit22", 12);
insert into stud ( id, name, age ) values (10, "nit10", 56);
i am prompted with an error message showing...
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 'mysql
nitish < nit.dat' at line 1 .... what to do?
Hmmm..I think I got it. Are you running MySQL already before executing that statement? In that case, the command fails. You need not have to connect to mysql and execute that query.
Refer this. The command is correct and it should work if the text file contains the INSERT query you have specified. If there is anything more then because of those query it should fail.
If you are a MySQL beginner you could try GUI tools where you don't have to worry about commands :-) Read this. You could try SQLyog which is simple and efficient.