Skip to content

x414i/MySQL-Seed-Extractor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MySQL Seed Extractor

Local PHP tool to extract ordered seed.sql files from MySQL/phpMyAdmin exports.

Features

  • Upload a .sql file exported from phpMyAdmin.
  • Parse CREATE TABLE, ALTER TABLE ... FOREIGN KEY, and multi-row INSERT INTO.
  • Detect tables, columns, primary keys, foreign keys, and dependency order.
  • Select one or more tables for export.
  • Include only selected tables, full parent tables, or FK-related parent rows.
  • Preview the generated SQL before downloading.
  • Export seed_selected_tables.sql with optional SET FOREIGN_KEY_CHECKS=0.

Requirements

  • PHP 8.1 or newer.
  • XAMPP, LAMPP, DDEV, or any local PHP server.
  • No database connection is required for the first version.

Run Locally

From the project directory:

php -S localhost:8000

Then open:

http://localhost:8000

With XAMPP/LAMPP, copy the mysql-seed-extractor folder into htdocs, then open:

http://localhost/mysql-seed-extractor

Quick Test

Use the included file:

examples/sample.sql

CLI test:

php tools/test_sample.php

Recommended test:

  1. Upload examples/sample.sql.
  2. Select posts.
  3. Keep الجداول المختارة + السجلات المرتبطة فقط.
  4. Preview the seed.

Expected result:

  • roles appears first.
  • users appears second.
  • posts appears last.
  • Only the parent rows required by selected post rows are included.

Project Structure

index.php
src/
  SqlTokenizer.php
  SqlParser.php
  SchemaAnalyzer.php
  ForeignKeyResolver.php
  SeedGenerator.php
assets/
  css/app.css
  js/app.js
storage/
  uploads/
  cache/
examples/
  sample.sql

Notes

This version is intentionally local-first. It does not execute imported SQL against a real MySQL server. The parser reads the SQL text, builds a schema model, resolves dependencies, and generates a new seed file from the parsed inserts.

For very complex dumps, the next improvement would be adding optional support for a mature MySQL parser library or importing into a temporary isolated database for deeper FK and row filtering.

About

A local PHP tool to extract ordered MySQL seed files from phpMyAdmin SQL dumps with foreign key dependency handling.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages