When there is a uniformity error in the contents of a database field, we can replace it using replace in the MySQL statement to replace the correct content with the wrong content.
Update table SET field name =replace (field name, ' replaced content ', ' replaced content ') where condition (also can not add, do not add all replace)
Column 1
The code is as follows |
Copy Code |
Update AAAA set Abcd=replace (ABCD, ' http://localhost/', ' http://www.111cn.net/') where pid>4 |
It means to replace the http://localhost/content in the field ABCD with the pic>4 in the table aaaa. http://www.111cn.net/
Example 2
The code is as follows |
Copy Code |
Mysql> Select Host,user from user where user= ' testuser '; +-----------------------+----------+ | Host | user | +-----------------------+----------+ | Localhost.localdomain | TestUser | +-----------------------+----------+ |
Update field host's content, change "main" to "slave", with replace
code is as follows |
copy code |
mysql> Update user set Host=replace (host, ' main ', ' slave ') where user= ' testuser '; Query OK, 1 row Affected (0.00 sec) Rows matched:1 changed:1 warnings:0 Mysql> Select Host,user from user where user= ' testuser '; +------------------------+----------+ | Host | user | +------------------------+----------+ | Localhost.localdoslave | TestUser | |
+------------------------+----------+
From query results to, data has been updated successfully