gpt4 book ai didi

mysql - 选择并替换mysql中的所有非键盘字符

转载 作者:行者123 更新时间:2023-11-30 00:37:39 26 4
gpt4 key购买 nike

这是我的代码。

SELECT * 
FROM `accounts`
WHERE NOT name REGEXP '^[[.NUL.]-[.DEL.]]*$'

我希望所有表格中的所有非键盘字符都替换为空格。

希望有人能真正做到这一点。

最佳答案

您将无法在 SQL 中轻松完成此操作。

最直接的方法是对数据库进行逻辑备份,使用 sed 或 perl (或一些类似的工具来进行字符串替换),然后重新导入数据。

您应该通过将数据导入测试数据库(或至少是测试架构)来对此进行测试,以确保它不会损害您的数据。

假设“非键盘”字符指的是“不可打印”字符,并且您在 Linux 上,则可以使用 mysqldump 和 sed 的组合来执行此操作,如下所示:

# dump your schema and data
mysqldump --single-transaction your_schema > /tmp/your_schema.sql

# copy the dump file and replace all non-printable characters with a space
sed -e 's/[^[:print:]]/ /g' /tmp/your_schema.sql > /tmp/your_schema_test.sql

# create an empty test schema to test the import
mysqladmin create your_schema_test

# import the data into the test schema
mysql -f your_schema_test < /tmp/your_schema_test.sql

关于mysql - 选择并替换mysql中的所有非键盘字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22025567/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com