Home >Database >Mysql Tutorial >How Can I Update MySQL URLs to a New Domain While Preserving File Names?
Batch update MySQL URL: keep file name
There is a table in your MySQL database whose url
field contains a URL like "https://www.php.cn/link/052a1a3c0142ad636571f88ea2506eac". You need to update these URLs to the new domain name "https://www.php.cn/link/c2be0c8ff27074343b8218c3b01bb3d0img1.jpg" while retaining the file name .
can be implemented in the REPLACE()
statement using the UPDATE
function:
<code class="language-sql">UPDATE urls SET url = REPLACE(url, 'https://www.php.cn/link/7cff4ce87d7f2179d73e7959bf213529', 'https://www.php.cn/link/c2be0c8ff27074343b8218c3b01bb3d0')</code>
In this query:
urls
is the name of the table containing the url
field. REPLACE(url, 'https://www.php.cn/link/7cff4ce87d7f2179d73e7959bf213529', 'https://www.php.cn/link/c2be0c8ff27074343b8218c3b01bb3d0')
Replace the substring 'url
https://www.php.cn/link/7cff4ce87d7f2179d73e7959bf213529' in the field value with 'https://www.php.cn/link/c2be0c8ff27074343b8218c3b01bb3d0'. After executing this query, all URLs in the url
field will be updated with the new domain name while retaining the filename. Note that this method relies on the consistency of the URL structure. If the URL structure is different, you need to adjust the parameters in the REPLACE()
function.
The above is the detailed content of How Can I Update MySQL URLs to a New Domain While Preserving File Names?. For more information, please follow other related articles on the PHP Chinese website!