我试图弄清楚如何在数据库中定位一个url的所有事件。我想搜索所有表和所有字段。但我不知道从哪里开始,甚至不知道是否有可能。


当前回答

在phpMyAdmin的搜索功能是可用的:

选择特定的数据库而不是表。 点击“搜索”标签 输入你想要的搜索词 选择要搜索的表

phpMyAdmin屏幕截图:

'Search'特性也可以在MySQL Workbench中使用:

数据库菜单>查询表数据 选择要搜索的数据库和表(只会在选定的表中搜索) 在搜索中你可以使用wildChars。

MySQL Workbench屏幕截图:

其他回答

我不记得我在哪里遇到这个脚本,但我一直在使用它与XCloner移动我的WP多站点。

<?php

    // Setup the associative array for replacing the old string with new string
    $replace_array = array( 'FIND' => 'REPLACE', 'FIND' => 'REPLACE');

    $mysql_link = mysql_connect( 'localhost', 'USERNAME', 'PASSWORD' );
    if( ! $mysql_link) {
        die( 'Could not connect: ' . mysql_error() );
    }

    $mysql_db = mysql_select_db( 'DATABASE', $mysql_link );
    if(! $mysql_db ) {
        die( 'Can\'t select database: ' . mysql_error() );
    }

    // Traverse all tables
    $tables_query = 'SHOW TABLES';
    $tables_result = mysql_query( $tables_query );
    while( $tables_rows = mysql_fetch_row( $tables_result ) ) {
        foreach( $tables_rows as $table ) {

            // Traverse all columns
            $columns_query = 'SHOW COLUMNS FROM ' . $table;
            $columns_result = mysql_query( $columns_query );
            while( $columns_row = mysql_fetch_assoc( $columns_result ) ) {

                $column = $columns_row['Field'];
                $type = $columns_row['Type'];

                // Process only text-based columns
                if( strpos( $type, 'char' ) !== false || strpos( $type, 'text' ) !== false ) {
                    // Process all replacements for the specific column                    
                    foreach( $replace_array as $old_string => $new_string ) {
                        $replace_query = 'UPDATE ' . $table . 
                            ' SET ' .  $column . ' = REPLACE(' . $column . 
                            ', \'' . $old_string . '\', \'' . $new_string . '\')';
                        mysql_query( $replace_query );
                    }
                }
            }
        }
    }

    mysql_free_result( $columns_result );
    mysql_free_result( $tables_result );
    mysql_close( $mysql_link );

    echo 'Done!';

?>

本视频的前30秒展示了如何使用Phpmyadmin的全局搜索功能 这很有效。它将在每个表中搜索字符串。

http://www.vodahost.com/vodatalk/phpmyadmin-setup/62422-search-database-phpmyadmin.html

如果你可以使用bash -这里有一个脚本: 它需要一个用户dbread,并在数据库上传递dbread。

#!/bin/bash
IFS='
'
DBUSER=dbread
DBPASS=dbread
echo -n "Which database do you want to search in (press 0 to see all databases): " 
read DB
echo -n "Which string do you want to search: " 
read SEARCHSTRING
for i in `mysql $DB -u$DBUSER -p$DBPASS -e "show tables" | grep -v \`mysql $DB -u$DBUSER -p$DBPASS -e "show tables" | head -1\``
do
for k in `mysql $DB -u$DBUSER -p$DBPASS -e "desc $i" | grep -v \`mysql $DB -u$DBUSER -p$DBPASS -e "desc $i" | head -1\` | grep -v int | awk '{print $1}'`
do
if [ `mysql $DB -u$DBUSER -p$DBPASS -e "Select * from $i where $k='$SEARCHSTRING'" | wc -l` -gt 1 ]
then
echo " Your searchstring was found in table $i, column $k"
fi
done
done

如果有人想要一个解释:http://infofreund.de/?p=1670

SQLyog是基于GUI的解决方案,可以跨所有列、表和数据库进行数据搜索。用户可以自定义搜索,将其限制为字段、表和数据库。

在它的数据搜索功能中,用户可以像使用谷歌一样搜索字符串。

一个简单的解决方案是这样做的:

mysqldump -u myuser --no-create-info --extended-insert=FALSE databasename | grep -i "<search string>"