#1064 Syntax Error, Simple Search and Replace Command? - mysql

Switching Wordpress databases, and I am attempting to run the Search and Replace command to change all the permalinks.
use ruepi;
update [table_name] set [field_name] =
replace([field_name],'[http://131.193.220.64/ruepi]','[http://ruepi.uic.edu]');
I am getting back:
SQL query:
UPDATE [table_name] SET [field_name] = REPLACE( [field_name],
'[http://131.193.220.64/ruepi]', '[http://ruepi.uic.edu]' ) ;
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 '[table_name] set [field_name] =
replace([field_name],'[http://131.193.220.64/rue' at line 1
Not sure exactly where my syntax is wrong? If anyone could look over this real quick.
Edit: Still getting #1146 error, which is the same error I got when previously trying this command:
update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, 'http://131.193.220.64/ruepi',
'http://ruepi.uic.edu/');
ERROR:
Error
SQL query:
UPDATE `table_name` SET `field_name` = 'http://131.193.220.64/ruepi' WHERE
`field_name` = 'http://ruepi.uic.edu';
MySQL said: Documentation
#1146 - Table 'ruepi.table_name' doesn't exist

This does not look like a valid mysql command i.e. using [] for the column names
Should be as
update table_name
set field_name =
replace(field_name,'http://131.193.220.64/ruepi','http://ruepi.uic.edu');

USE ruepi;
UPDATE `table_name` set `field_name` = 'http://131.193.220.64/ruepi'
where `field_name` = 'http://ruepi.uic.edu';
Try this.

Related

Update longtext field in mysql

Im trying to update a longtext type field called 'comment' using a simple sql query in mysql client like this :
Update mytable set comment='Test' where id = 1;
But i'm getting this error
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 'comment='Test' where id = 1' at line 1
Am i missing something ?, thanks in advance.
comment is a reserved word, if you want to have a table/field with that name, you have to quote it (or use the table.fieldname syntax, in case of a field). default in mysql is the backtick for that, so:
update mytable set `comment`='Test' where id = 1;
Found it, it gets solved with this:
update mytable as a set a.comment='Test' where id = 1;

Error with MySQL insert query

insert into sws(grade) values(100) where student_id='$session_id' & cys='$get_id2'
It shows error as
You have an error in your sql syntax; check manual that corresponds to your MYSQL server version for right syntax to use near 'WHERE student_id='21' & cys='java' at line 1
Use Update Command not Insert
Replace the & with AND (read about MySQL AND syntax).
INSERT syntax cannot have WHERE clause as you used, you might want to use UPDATE.
Basic UPDATE syntax :
UPDATE table_name
SET column1 = value1, column2 = value2...., columnN = valueN
WHERE [condition];

MySQL query with enum values

I've the following structure in MySQL 5.6.19.
CREATE TABLE `metadata` (
`md5` char(32) NOT NULL,
`match` enum('none','md5','similarity') DEFAULT NULL
)
And I got an error doing a query like this:
select * from metadata where match = 'md5';
The error is:
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 '= 'md5'' at line 1
There're multiple entries in the table and rows that could match the query. But MySQL refuse to do it. Any idea about the reason?
Thanks!
MATCH is reserved keyword in MySQL: http://dev.mysql.com/doc/mysqld-version-reference/en/mysqld-version-reference-reservedwords-5-5.html. You should enclose your field name in backticks to make it work:
select * from metadata where `match` = 'md5';

Update a column on rows of which another column has multiple values

I am having trouble with something like this:
UPDATE `database` SET `col1` = 0 WHERE `col2` in (1,2,3,4);
Following is an actual failed query.
Error Message:
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 '#cc3.biz, sales#allservico.com)' at line 1
SQL:
UPDATE `CubeCart_customer` SET `optIn1st` = 0 WHERE `email` in (markscarts#cc3.biz, sales#allservico.com);
I have searched the web, and here, and tried several variations in my code to produce the query, but I just can't pinpoint where I'm failing.
Any light on this matter would be greatly appreciated.
You need quotes around your string values
UPDATE CubeCart_customer
SET optIn1st = 0
WHERE email in ('markscarts#cc3.biz', 'sales#allservico.com');

what wrong with my mySQL query using REGEX and or operator?

I have a script that is generating queries like this one by grabbing categories and keywords from the database. However something is wrong with the syntax it seems. here is the code first:
UPDATE `mrhowtos_main`.`eng-jap` SET `category` = 'travel' WHERE `eng` REGEXP 'abroad|country|sight seeing|foreign|plane|train|bus' and where `category` REGEXP 'misc|none';
and here is the error returned by mySQL:
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 'where category REGEXP 'misc|none'' at line 1
I have looked at it for a long time and still dont seem to see what is wrong with it. im certain the error is not in the table or column names in the DB.
The second where shouldn't be there. Try:
UPDATE `mrhowtos_main`.`eng-jap` SET `category` = 'travel' WHERE `eng` REGEXP 'abroad|country|sight seeing|foreign|plane|train|bus' and `category` REGEXP 'misc|none';