mysql替换表的字段里面内容,如例子:
mysql> select host,user from user where user='testuser';
+-----------------------+----------+
| host | user |
+-----------------------+----------+
| localhost.localdo main | testuser |
+-----------------------+----------+
update字段host的内容,把 "main"改成 "slave", 用REPLACE
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.localdo slave | testuser |
+------------------------+----------+
由查询结果到,数据已经更新成功
mysql> select host,user from user where user='testuser';
+-----------------------+----------+
| host | user |
+-----------------------+----------+
| localhost.localdo main | testuser |
+-----------------------+----------+
update字段host的内容,把 "main"改成 "slave", 用REPLACE
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.localdo slave | testuser |
+------------------------+----------+
由查询结果到,数据已经更新成功