通常我使用手动查找替换文本在MySQL数据库使用phpMyAdmin。我现在厌倦了,我怎么能运行一个查询,在phpMyAdmin的整个表中找到和替换一个新的文本?
例如:查找关键字domain。例如,替换为www.domain.example。
通常我使用手动查找替换文本在MySQL数据库使用phpMyAdmin。我现在厌倦了,我怎么能运行一个查询,在phpMyAdmin的整个表中找到和替换一个新的文本?
例如:查找关键字domain。例如,替换为www.domain.example。
当前回答
在phpMyAdmin中运行SQL查询来查找和替换所有WordPress博客文章中的文本,例如查找mysite。Example /wordpress,然后用mysite。Example /news替换 本例中的表为tj_posts
UPDATE `tj_posts`
SET `post_content` = replace(post_content, 'mysite.example/wordpress', 'mysite.example/news')
其他回答
phpMyAdmin包含一个简洁的查找和替换工具。
选择表,然后点击Search > Find and replace
这个查询花费了大约一分钟的时间,成功地替换了几千个oldurl实例。用新url进行扩展。列post_content中的ext
这个方法最棒的地方是:你可以在提交之前检查每个匹配。
注意:我使用phpMyAdmin 4.9.0.1
把它放到一个php文件中,然后运行它,它应该做你想做的事情。
// Connect to your MySQL database.
$hostname = "localhost";
$username = "db_username";
$password = "db_password";
$database = "db_name";
mysql_connect($hostname, $username, $password);
// The find and replace strings.
$find = "find_this_text";
$replace = "replace_with_this_text";
$loop = mysql_query("
SELECT
concat('UPDATE ',table_schema,'.',table_name, ' SET ',column_name, '=replace(',column_name,', ''{$find}'', ''{$replace}'');') AS s
FROM
information_schema.columns
WHERE
table_schema = '{$database}'")
or die ('Cant loop through dbfields: ' . mysql_error());
while ($query = mysql_fetch_assoc($loop))
{
mysql_query($query['s']);
}
UPDATE `MySQL_Table`
SET `MySQL_Table_Column` = REPLACE(`MySQL_Table_Column`, 'oldString', 'newString')
WHERE `MySQL_Table_Column` LIKE 'oldString%';
在有大小写字母的句子中, 我们可以使用二进制REPACE
UPDATE `table_1` SET `field_1` = BINARY REPLACE(`field_1`, 'find_string', 'replace_string')
最好你把它导出为SQL文件,用visual studio代码等编辑器打开,然后找到并重新排版你的文字。 我在1分钟内替换1gig文件SQL 16个字,总共是14600个字。 这是最好的办法。 替换后保存并再次导入。 不要忘记压缩它与zip导入。