mysql DB Import script issue on version 5.6 - mysql

I have a production server that hosts mysql 5.0 database. From there I exported the db backup script using export feature provided in phpmyadmin.
Now I want to restore database script on new server that 5.6 mysql. But when I run the import script I get following error:
Error Description:
unexpected character. (near at position mysql
On further investigation I found that the query was getting break at following location, please see image given below:
I noticed that this scring variable has 102129 Characters I also verified that I put '' in starting or in between then it does not break, but after n character it breaks & quite visible in phpmyadmin editor.
I am aware of using \' escape specifier, but this option is not useful in my case as this script is really long I manually can't replace such occurrances.
Please suggest any really healping solution.
Info:
While I was writing this post, I tried to execute the DB Script for single Record only (i.e., removing all other script) then i executed successfully. Therefore I can't identify the real reason for this issue.
Please suggest any db migration technique that I can use in this scenario.
Thanks
EDIT:
Following is the query that is being throwing exception on production phpmyadmin, but working elsewhere:
INSERT INTO `wp_options` (`option_id`, `option_name`, `option_value`, `autoload`, `blog_id`) VALUES
(297, 'wpcs_options', 'a:40:{s:5:"width";s:3:"973";s:6:"height";s:3:"399";s:12:"border_width";s:1:"0";s:12:"border_color";s:7:"#ffffff";s:11:"font_family";s:39:"\\''Trebuchet MS\\'', Helvetica, sans-serif";s:9:"font_size";s:2:"12";s:5:"color";s:7:"#000000";s:12:"heading_font";s:2:"18";s:13:"heading_color";s:7:"#ffffff";s:16:"background_color";s:7:"#ffffff";s:6:"update";s:7:"UPDATED";s:16:"square_per_width";s:1:"7";s:17:"square_per_height";s:1:"5";s:5:"delay";s:4:"3000";s:6:"sDelay";s:2:"30";s:7:"opacity";s:3:"0.7";s:10:"titleSpeed";s:3:"500";s:6:"effect";s:6:"random";s:10:"hoverPause";s:4:"true";s:24:"navigation_next_previous";s:4:"true";s:18:"navigation_buttons";s:4:"true";s:16:"navigation_color";s:7:"#000000";s:12:"show_excerpt";s:5:"false";s:11:"char_length";s:3:"200";s:10:"new_window";s:5:"false";s:5:"order";s:5:"false";s:12:"custom_image";s:4:"true";s:13:"post_category";s:1:"0";s:15:"number_of_posts";s:1:"4";s:19:"no_of_custom_images";s:1:"5";s:12:"slide_image1";s:92:"http://mydemozone.com/signaturewellnessv2/wp-content/plugins/content-slide/images/image1.jpg";s:16:"slide_imagelink1";s:60:"http://www.snilesh.com/resources/jquery/jquery-image-slider/";s:12:"slide_image2";s:92:"http://mydemozone.com/signaturewellnessv2/wp-content/plugins/content-slide/images/image2.jpg";s:16:"slide_imagelink2";s:132:"http://www.snilesh.com/resources/wordpress/wordpress-tips-and-tricks/wordpress-show-title-and-excerpt-of-child-pages-on-parent-page/";s:12:"slide_image3";s:92:"http://mydemozone.com/signaturewellnessv2/wp-content/plugins/content-slide/images/image3.jpg";s:16:"slide_imagelink3";s:90:"http://www.snilesh.com/resources/wordpress/wordpress-plugins/wordpress-news-ticker-plugin/";s:12:"slide_image4";s:92:"http://mydemozone.com/signaturewellnessv2/wp-content/plugins/content-slide/images/image4.jpg";s:16:"slide_imagelink4";s:66:"http://www.snilesh.com/resources/jquery/jquery-image-sliders-2010/";s:12:"slide_image5";s:92:"http://mydemozone.com/signaturewellnessv2/wp-content/plugins/content-slide/images/image5.jpg";s:16:"slide_imagelink5";s:65:"http://www.snilesh.com/resources/jquery/jquery-dynamic-selectbox/";}', 'yes', 0);
The above query returns following error:
Error
Static analysis:
1 errors were found during analysis.
Ending quote ' was expected. (near "" at position 349)
SQL query:
INSERT INTO `wp_options` (`option_id`, `option_name`, `option_value`, `autoload`, `blog_id`) VALUES (297, 'wpcs_options', 'a:40:{s:5:"width";s:3:"973";s:6:"height";s:3:"399";s:12:"border_width";s:1:"0";s:12:"border_color";s:7:"#ffffff";s:11:"font_family";s:39:"\\''Trebuchet MS\\'', Helvetica, sans-serif";s:9:"font_size";s:2:"12";s:5:"color";s:7:"
MySQL said: Documentation
#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 ''a:40:{s:5:"width";s:3:"973";s:6:"height";s:3:"399";s:12:"border_width";s:1:"0";' at line 2

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

MySQL error "An alias was previously found" when an alias isn't in the query

I have a very odd error while trying to perform an update on a database. This is on an Ubuntu 16.04 server using MySQL 5.7.19-0ubuntu0.16.04.1. The query is:
UPDATE athlet_teamseason SET offkeyreturners = 'test' WHERE athlet_teamseason.id = 29701;
The MySQL error is:
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 'offkeyreturners = 'test' WHERE athlet_teamseason.id = 29701' at line 1
I am doing this in phpMyAdmin, and it gives a bit more information:
2 errors were found during analysis.
An alias was previously found. (near " " at position 50)
An alias was previously found. (near "'test'" at position 51)
If I try this update directly in the phpMyAdmin user interface (search for record, edit field value, submit form) it works, and the query shown is:
UPDATE athlet_teamseason SET offkeyreturners = 'test' WHERE athlet_teamseason.id = 29701;
which appears to be identical. HOWEVER, if I do a string comparison between the two I get:
So while they appear to be the same, there is a difference somewhere.
The queries were created from a table in a database, using concatenation and referencing cells in a source table. For example:
="UPDATE athlet_teamseason SET offkeyreturners = '"&data!I2&"' WHERE athlet_teamseason.id = "&data!A2&";"
I have thousands of these and they all produce the same error. I've done this dozens of times in older servers, might be an issue with MySQL 5.7?
Thanks to Uueerdo, I eliminated non-printing characters in my query.

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)

(ASP) MS Access -> MySQL: Error in Select, where [..] strings

I am using a portal system on my website and modified the ASP code heavily.
Since the website is growing, I want to migrate from MS Acces to MySQL.
Now, I think the portal I'm using (and some code I inputted) aren't MySQL compatable, because when I switch to the MySQL database, I get the following error.
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[MySQL][ODBC 5.1 Driver][mysqld-5.1.55-community]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 '[EzModuleID],
[ModName] From EzCore_Plugin Where IsModActive='1'' at line 1
[website]\WWWROOT\BOXX\INCLUDES../../includes/include.asp, line 3736
The SQL string regarding this line is the following:
Select [EzModuleID], [ModName] From EzCore_Plugin Where [IsModActive] = 1;
Im new to MySQL and I can't find why this is giving an error.
I've tried the quote's around 1, removing [], removing the space..
I think that when I figure out why this is causing an error, I can continue modifying the rest to make the website work on mysql.
Lose the square brackets
(I might as well post this as the answer rather than a comment)
In MySQL column and table names can be escaped with the backtick character ` or if the ANSI SQL mode is enabled with double quotes ".
Your WHERE clause (according to the error message) is Where IsModActive='1'. This works if IsModActive is a text column. If it is numeric, drop the single quotes. If IsModActive is a Boolean, change the clause to Where IsModActive IS true.
See: is operator