替换 mysql 数据库中的字符

发布于 2024-08-15 02:13:49 字数 328 浏览 3 评论 0原文

我已将大型 phpbb3 数据库从 latin1 数据库转移到 utf-8 一切顺利,现在我需要更改数据库中的“奇怪”字符。昨天我找到了一个有效的方法,现在我找不到了,我尝试过:

update phpbb_topics set topic_title = replace(topic_title, 'Ã', 'à');
update phpbb_topics set topic_title = replace(topic_title, 'è', 'è');

基本上我需要将表字段中的所有 à 字符更改为 à 等。

你怎么能这样做呢?

谢谢

I have transfered a big phpbb3 database from a latin1 database to an utf-8
Everything went ok, now I need to change the "strange" characters in the database. Yesterday I found a method that worked, now I can't find it anymore, I tried:

update phpbb_topics set topic_title = replace(topic_title, 'Ã', 'à');
update phpbb_topics set topic_title = replace(topic_title, 'è', 'è');

Basically I need to change all the à characters in the table field to à and so on.

How can you do this?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

溇涏 2024-08-22 02:13:49

更新 phpbb_topics 设置 topic_title = 替换(replace(topic_title, 'è', 'è'), 'à', 'à');

您应该回答自己以下问题:

  • 数据库中存储了哪些二进制数据(使用 ascii() 函数或 SELECT ... INTO DUMPFILE) 将
  • 哪些二进制数据发送到客户端(并不总是与存储的相同)
  • 客户端如何显示已收到二进制数据? (尝试不同的客户端和不同的选项)

update phpbb_topics set topic_title = replace(replace(topic_title, 'è', 'è'), 'Ã', 'à');

You should answer yourself following questions:

  • what binary data is stored in database (use ascii() function or SELECT ... INTO DUMPFILE)
  • what binary data is sent to client (it is not always the same as stored)
  • how your client shows received binary data? (try different clients and different options)
瑶笙 2024-08-22 02:13:49

我会将其转储到 .sql 文件,然后用 sed 或文本编辑器替换字符(如果文件不太大)。之后再次运行该脚本。
也许有一种方法可以直接在数据库中执行此操作,但我不知道。

我的解决方案的问题在于它不是原子的。转储和重新插入之间对数据库的更改将会丢失。

问候
拉斐尔

I would dump it to a .sql file and then replace the chars with sed or a text editor( if the file is not to large). After that you run the script again.
Maybe there is a way to do this in the database directly but I don't know it.

The problem about my solution is that its not atomic. Changes to the db between the dump and the reinsertion are lost.

Greetings
Raffael

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文