简体   繁体   中英

MySQLAdmin replace text in a field with percent in text

Using MySQLAdmin. Moved data from Windows server and trying to replace case in urls but not finding the matches. Need slashes as I don't want to replace text in anything but the urls (in post table). I think the %20 are the problem somwhow?

UPDATE table_name SET field = replace(field, '/user%20name/', '/User%20Name/')

The actual string is more like:

https://www.example.com/forum/uploads/user%20name/GFCI%20Stds%20Rev%202006%20.pdf

In a case you are using MariaDB you have REGEXP_REPLACE() function.

But best approach is to dump the table into the file. Open it in a Notepad ++

and run regex replace like specified on a pic: Pattern is: (https:[\\/\\w\\s\\.]+uploads/)(\\w+)\\%20(\\w+)((\\/.*)+) Replace with: $1\\u$2\\%20\\u$3$4

在此处输入图片说明

Then import the table again Hope this help

如果是MariaDB,则可以执行以下操作:

UPDATE table_name SET field = REGEXP_REPLACE(field, '\/user%20name\/', '\/User%20Name\/');

First, please check, what is actually stored in the database: %20 is a html-entity which represents a whitespace. Usually, when you are storing this inside the database, it will be represented as an actual whitespace (converted before you store it) -> Hence your replace doesn't match the actual data.

The second option that might be possible - depending on what you want to do: You are seeing the URL containing %20 , therefore you created your database records (which you would like to fetch) with that additional %20 - And when you now try to query your results based on the actual url, the %20 is replaced with an "actual" whitespace (before your query) and hence it doesn't match your stored data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM