Skip to main content

Find string anywhere in database

Project description

SQLGrep: Grep in MySQL database tables / fields

If you do not know db schema (drank a lot yesterday, first day on new project or hacking alien starhip database)

SQLGrep will examine db schema and search (SELECT ... WHERE ...) for specified text/number/regex/like (needle) in all fields of all tables.

Install

To install mysql version on debian you may need to:

apt install pkg-config libmariadb-dev python3-dev gcc

Installation:

# new way, use pipx if you can (with mysql packages)
pipx install sqlgrep[mysql]

# old-fashioned way  (and postgresql support)
pip install sqlgrep[postgresql]

Examples

I use test db with just one table, so all found records will be in "libro" table.

# We want to know where year is stored and we know, at least one book published in 1991
# found in table libro, fields: masterid, id, anno, peso
$ sqlgrep mysql://localhost/libro --limit 1 1991
libro(id=1991) masterId: 1991
libro(id=1991) id: 1991
libro(id=80) anno: '1991'
libro(id=169601) peso: 1991

# LIKE search, I'm only interested in mice...
$ sqlgrep mysql://localhost/libro --like %mice%
libro(id=149894) autore: 'Primicerj Giulio'
libro(id=37004) title: 'ECONOMICESKAIA GHEOGRAFIA SSSR. - Lialikov H.I. - 1961'
libro(id=1359) titolo: 'STUDI MICENEI ED EGEO-ANATOLICI. Fascicolo ottavo.'
libro(id=1367) titolo: 'IL TORO DI MINOSSE. Creta, il Minotauro e la civiltà micenea.'

To look in database via socket connection use URL mysql:///dbname .

Speed

sqlgrep does one SQL SELECT ... WHERE query for each field in database. So, for db of 5 tables and 10 fields in each, there will be 50 queries (sending query to db is very simple and fast operation). All filtering are performed on database side (not in our slow python code), so it goes with maximal speed.

Database credentials

Specify database as SQLAlchemy URL like mysql://user:password@host/db_name (or postgresql://...)

See SQLAlchemy Engine Configuration for details.

Usage

usage: sqlgrep [-h] [--host HOST] [-t TABLES [TABLES ...]] [--like] [--float] [--int] [--limit N] [-c] [--all]
               DB URL needle

database search (SQL grep), version: 0.0.6

positional arguments:
  DB URL                example: mysql://user:password@host/db_name
  needle

options:
  -h, --help            show this help message and exit
  --host HOST
  -t TABLES [TABLES ...], --tables TABLES [TABLES ...]
                        tables (default: all)
  --like                use SQL LIKE instead of =

Types (default - string):
  --float               coerce to float
  --int                 coerce to integer

Output:
  --limit N             Limit to N results for each column
  -c, --count           Count only
  --all                 display ALL fields from matching rows

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sqlgrep-0.0.14.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sqlgrep-0.0.14-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file sqlgrep-0.0.14.tar.gz.

File metadata

  • Download URL: sqlgrep-0.0.14.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.0

File hashes

Hashes for sqlgrep-0.0.14.tar.gz
Algorithm Hash digest
SHA256 e3b53cdd58229e73e400dee99a40696f2b28e51c0d6478f89b3d0927d9bc5f92
MD5 bb1cd89b0b34e6998a98c529114b7551
BLAKE2b-256 7b2c8856dbed12f7e697c83010f32f41bf08a442380cf424e8d0476de7bb95b0

See more details on using hashes here.

File details

Details for the file sqlgrep-0.0.14-py3-none-any.whl.

File metadata

  • Download URL: sqlgrep-0.0.14-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.0

File hashes

Hashes for sqlgrep-0.0.14-py3-none-any.whl
Algorithm Hash digest
SHA256 82c6523339f6c360b16197fa9335c4f52795314f6875d601de540ea190479069
MD5 f6458d0b54209f0c8bfe7fa506aba719
BLAKE2b-256 401545ec1bf0c5b7d6c082a0e803891ab8319d8c2eaf54ae3baa34a40792622b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page