restore mysql backup file using php - mysql

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.

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

is there a Syntax like MSSQL's "INSERT INTO table (fieldlist) OUTPUT INSERTED.id VALUES" in MySQL?

I like to get the id of the record that's been inserted by a statement as a result of that statement. I know about SELECT LAST_INSERT_ID(); but can not use it in my scenario because LAST_INSERT_ID() works on a per-connection-basis and I am currently using a convenient function in my framework to access the db - but that convenience implies that the connection only exists during execution of that statement - so I'm wondering if there is a syntax as in Microsoft SQL Server as shown in the title?
In my environment, I am building the command looks like this:
INSERT INTO Bookings (Status,YEarlyBird,YDays,YHotel,YBanquet,Name,Company,Address,Town,Region,Postcode,CountryCode,Second
Name,SecondEmail,RoomType,SpouseMealPlan,Notes,Conference_VAT,Accommodation_VAT,Conference_id,InvoiceAmount,Conferen
ceGross,Accomodation,SpouseGross,SpouseNet,TotalGross,TotalNet,ConferenceNet,Courses) VALUES (:<C1:,:<C1:,:<C6:,:<C
6:,:<C1:,:<C12:,:<C28:,:<C15:,:<C7:,:<C5:,:<C5:,:<C2:,:<C1:,:<C1:,:<C15:,:<C3:,:<C1:,:<F:,:<F:,:<I:,:<F:,:<F:,:<F:,:
<F:,:<F:,:<F:,:<F:,:<F:,:<C1:);SELECT LAST_INSERT_ID();
(the :<:-stuff are placeholders for Bind-variables)
If a ran the INSERT on its own, it works. If I append the SELECT LAST_INSERT_ID() as shown, I get:
[MySQL][ODBC 5.3(w) Driver][mysqld-5.7.18-log]You have an error in your SQL syntax; check the manual that corresponds to y
our MySQL server version for the right syntax to use near 'SELECT LAST_INSERT_ID()' at line 1
P.S: using that convient way to access the DB is perfectly ok in my use-case because the DB is written once only - exactly with the statement i am working on.

mysql DB Import script issue on version 5.6

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

Error while inserting picture into sql table

I am trying to insert a 'png ' image into an sql table field(called barchart,which is of type blob) with the below query.
INSERT INTO disease_symptom_soc(barchart) Values ((SELECT BULKColumn FROM OPENROWSET(BULK N'/home/barchartC2936861.png', SINGLE_BLOB) AS Image)) where disease_id='C2936861';
I am getting the below error.What could be the reason?
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 '(BULK N'/home/barchart' at line 1
i guess u can use LOAD_FILE
Example:
INSERT INTO expBLOB(ID,IMAGE) VALUES(1,LOAD_FILE('/some/path/image.png'))
If you can, then change the DataType of the column to 'image'. Depending on the sql server version you are using. Otherwise if it oracle based db , you will have to create a loadfile proc and execute it as follows:
http://arjudba.blogspot.com/2008/06/how-to-insert-blob-dataimage-video-into.html
MySql OpenrowSet isn't used to copy files into the database but to query an external file (csv, xls) with a connection string, for example
OPENROWSET ('MSDASQL','mysql connection string','query')
I suggest you to load the file with a simple program made in any language (I don't know if you are developing in php, c#...) and pass it already loaded in memory to the db with a simple insert query.

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.