I have a database and i have a home URL that I want to change into another one. The problem is that this home URL is used in a lot of table and in a lot of column.
So is there a MySQL request that do something like :
UPDATE * SET * = REPLACE(*, 'old-url', 'new-url') WHERE * LIKE '%old-url%'
?
Have a good day ! :)
You could use the plugin "Go Live Update URLS". You just enter the old & new URL and select the tables you want to replace the value.
https://nl.wordpress.org/plugins/go-live-update-urls/
Back-up your database before executing the replacement!
Related
and thanks in advance for any help. I'm working on fixing all broken links in a massive WordPress multisite database and need some help writing an SQL query to run via PHP MyAdmin. I've searched, but can't the perfect solution...
PROBLEM: We have more than a thousand broken links that start with http:/ instead of http://
CHALLENGE: The following would result in numerous links starting with http:///
UPDATE wp_1_posts
SET post_content = replace (post_content,
'http:/',
'http://');
PROCESS: I want to write a query to SELECT all these links first, so I can review them to ensure I don't do any damage when replacing the text string. Downloading a db dump and doing a manual S&R is not an option since we're talking about a multi-gigabyte database.
I thought something like this would work...
SELECT * FROM wp_1_posts
WHERE post_content LIKE '%http:/%'
AND WHERE post_content NOT LIKE '%http://%'
But that just throws a syntax error. Am I even close?
QUESTION #1: How can I find all instances of "http:/" without returning all "http://" instances in the query results.
QUESTION #2: How might I safely fix all instances of "http:/" without affecting any "http://" strings.
FYI: I'll admit I know just enough about this to be dangerous, and I am not familiar with regular expressions. at. all. That's why I'm turning to you for help. Thanks again!
This should work, in MYSQL:
UPDATE wp_1_posts SET post_content = replace(post_content,'http:/', 'http://')
WHERE post_content REGEXP 'http:/[^/]'
I'm almost done transferring/reconstructing a substantial mysql db for new application. Column 'website' shows 'www.example.com'. Because the new application reads it as a hyperlink, I need the column to read 'http://www.example.com'. Is there a way to add the 'http://' in the beginning of each record for that column? Thanks in advance!
You can use the CONCAT function to do that:
UPDATE tbl SET website=CONCAT('http://', website);
If you want to get cleverer and only update columns which don't already have http:// prepended, try
UPDATE tbl SET website=CONCAT('http://', website)
WHERE website NOT LIKE 'http://%';
Update
To prevent update to columns that have no site in them currently use this
UPDATE tbl SET website=CONCAT('http://', website)
WHERE website NOT LIKE 'http://%' AND website<>'';
You can use the concat command. Something like
SELECT CONCAT('http://', website) FROM table
Use concat to generate the new column:
UPDATE table1 SET website = CONCAT("http://", website);
You might read this question every day so i tried another Stackoverflow's answer before asking:
CakePHP table is missing even when it exists
Anyways. The table i try to select data from does exist (quadra-checked uppercase/lowercase!) and it gets also listed via $db->->listSources().
Here's a screenshot of the query, the message and the last result from listing all Datasource's tables:
http://i.stack.imgur.com/CdhcV.png
Note: If i run this query in PHPMyAdmin manually it works fine. I would say its impossible to get the pictures output at one time in a view - now its up to you to tell me the opposite. By the way: I am pretty sure to use the correct Datasource.
I should tell additionally that the mysql-server is hosted on another platform. Since i can use it for my localhost-phpmyadmin if i modify the config.inc.php i can promise it is no Firewall-Problem.
Written in behalf of xcy7e:
The mistake was to execute the Query from the local Model. Here's the code:
$conn = ConnectionManager::getDataSource('myDB');
$conn->query($query);
// instead of $this->query($query);
I am trying to transfer a couple of columns from an old database to a live database.. The issue I have is that I need the columns to match up with a column on the live database. For instance let me use an example: My live database has a table like this
TABLE NAME is ITEMS Then inside the table there would be a columns name ItemLookUp and ExtensionDescription.
So the live table would look something like this:
**ItemLookUp** **ExtensionDesctiption**
AAA-06-201 'Blank'
BBB-08-201 'Blank'
CCC-99-201 'Blank'
The old database would look like this:
**ItemLookUp** **ExtensionDescription**
AAA-06-201 Toy part
BBB-08-201 Mechanic Part
CCC-99-201 2x1 Screw
So what I am trying to do is make the live database have the information of the old database, but the ExtensionDescription needs to match up with the ItemLookup meaning for example if the ItemLookUp is AAA-06-201 it must have an ExtensionDescription of Toy part... Any help would be greatly appreciated.
Try on this. I thik this will help you.
update tbnew
set tbnew.ExtensionDesctiption = tbold.ExtensionDesctiption
from tbold
where
tbnew.ItemLookUp = tbold.ItemLookUp
UPDATE dbnew.items a JOIN dbold.items b
ON a.ItemLookUp=b.ItemLookUp
SET a.ExtensionDescription=b.ExtensionDescription
Assuming same server.
Figure it out.. Thanks for all your help
update Item
set ExtendedDescription = X.ExtendedDescription
from Item I
INNER JOIN /old db name/raxx.dbo.Item X on I.ItemLookupCode = X.ItemLookupCode
WHERE I.ItemLookupCode = X.ItemLookupCode AND I.ExtendedDescription like ''
I need to check phone number to see if they match but the issue is, that one table is in database A and another is in database B.
I am wondering is there away to do a search like this:
update `chk_dup`, new set chk_dup.dup='Y' WHERE chk_dup.phone = new.phone;
But I guess I would need to do something like this:
update `A.chk_dup`, B.new set A.chk_dup.dup='Y' WHERE A.chk_dup.phone = B.new.phone;
I any one knows how to search two tables in completely different databases that would help.
I think in your second one you had a syntax error, try this one:
UPDATE `A`.`chk_dup`, `B`.`new`
SET `A`.`chk_dup`.`dup`='Y'
WHERE `A`.`chk_dup`.`phone` = `B`.`new`.`phone`;