Skip to main content

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

Metadata

Release files for sqlgrep 0.0.14

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sqlgrep 0.0.14
File Size Uploaded Provenance
sqlgrep-0.0.14.tar.gz 5.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for sqlgrep 0.0.14
File Interpreter ABI Platform
sqlgrep-0.0.14-py3-none-any.whl Python 3 none any Details

Total release size: 11.2 kB

Release files / sqlgrep-0.0.14.tar.gz

Download URL sqlgrep-0.0.14.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e3b53cdd58229e73e400dee99a40696f2b28e51c0d6478f89b3d0927d9bc5f92
BLAKE2b-256 checksum
How to use checksums
7b2c8856dbed12f7e697c83010f32f41bf08a442380cf424e8d0476de7bb95b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.27.0

Release files / sqlgrep-0.0.14-py3-none-any.whl

Download URL sqlgrep-0.0.14-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
82c6523339f6c360b16197fa9335c4f52795314f6875d601de540ea190479069
BLAKE2b-256 checksum
How to use checksums
401545ec1bf0c5b7d6c082a0e803891ab8319d8c2eaf54ae3baa34a40792622b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.27.0

Security for sqlgrep 0.0.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page