【发布时间】:2019-09-27 18:46:49
【问题描述】:
我看到了在 MySQL/MariaDB 数据库中替换   的 SQL 示例:
UPDATE wp_posts SET post_content = REPLACE(post_content, ' ', ' ');
...但是这个语句会抛出一个错误:
#1064 - You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to
use near '' )' at line 1
我看到了 '' 和 )' - 我尝试使用反斜杠 \ 转义分号:
UPDATE wp_posts SET post_content = REPLACE(post_content, ' \;', ' ');
...但得到相同的错误。实际上,我看到很多 MySQL/MariaDB 的 SQL 示例,它们并没有转义分号或 & 符号。
编辑
@Barmar 建议从命令行运行 SQL。我登录 MariaDB 并输入了 use 'use mydatabase'。提示更改为指示当前数据库,我输入了上述命令。该命令被正确接受,找到了 2300 多个匹配项,但没有任何更改:
MariaDB [mydatabase]> UPDATE wp_posts SET post_content = REPLACE(post_content, 'Â ', ' ');
Query OK, 0 rows affected (0.25 sec)
Rows matched: 2330 Changed: 0 Warnings: 0
为什么没有任何改变?
编辑 - 包括 WHERE
我越来越糊涂了。从 phpMyAdmin 内部:
SELECT * from wp_posts WHERE post_content LIKE '%Â %';
在 phpMyAdmin 中也是如此:
UPDATE wp_posts SET post_content = REPLACE(post_content, 'Â ', ' ') WHERE post_content LIKE '%Â %';
从 CLI:
SELECT COUNT(*) from wp_posts WHERE post_content LIKE 'Â ';
SELECT COUNT(*) from wp_posts WHERE post_content LIKE 'Â';
我完全不知道该如何看待这些差异。当然,我知道我的 wp_posts 中到处都是时髦的 Â。我可以使用 phpMyAdmin 在数据中看到它。
【问题讨论】:
-
你确定你的代码中没有
'&nbsp)(没有结束引号)吗? -
@jpaugh 绝对确定。这是一行 SQL。我已经盯着它看了太久...... SQL 是在我的问题中显示的第一个
UPDATE ...中复制/粘贴的。你一定是在告诉我它应该按原样工作吗? -
听起来像是一个 PhpMyAdmin 的 bug,可能是因为它在浏览器中运行,而
 对浏览器有特殊的意义。它可能试图阻止 XSS 并弄乱查询。 -
@jpaugh 我刚试过。将
 替换为' '后没有错误 - 但奇怪的是 Simulate 没有显示单个空格的匹配项。 -
只需输入
mysql,您将收到mysql>提示。在那里输入您的查询。输入quit退出。[
标签: mysql phpmyadmin mariadb