A CLI tool for performing bulk search-and-replace operations across all tables in a MySQL database. Connects to your database, scans all tables and their text columns, and replaces specified strings throughout your data.
- Scans all tables in a MySQL database
- Automatically identifies text-based columns (CHAR, VARCHAR, TEXT types)
- Performs row-by-row replacements with detailed logging
- Reports total replacements made per table
- Safe handling of NULL values
- Go 1.20 or higher
- MySQL database access
git clone https://github.com/wltechblog/mysqlreplace.git
cd mysqlreplace
go build -o mysqlreplace main.go./mysqlreplace [OPTIONS]-user string- MySQL username-database string- Database name-search string- String to search for
-host string- MySQL host (default: "localhost")-port int- MySQL port (default: 3306)-password string- MySQL password (default: empty)-replace string- String to replace with (default: empty)
Basic usage with password:
./mysqlreplace -user root -password secret -database myapp -search "old.domain.com" -replace "new.domain.com"With custom host and port:
./mysqlreplace -user admin -password pass123 -host db.example.com -port 3307 -database production -search "http://" -replace "https://"Delete a specific string (replace with empty):
./mysqlreplace -user root -database myapp -search "deprecated phrase" -replace ""- Connects to the specified MySQL database
- Retrieves a list of all tables
- For each table:
- Analyzes table structure to identify text columns
- Iterates through all rows
- Checks each text column for the search string
- Updates rows where replacements are needed
- Reports total replacements made per table and overall
- Always backup your database before running bulk replacements
- Test with a subset of data first if possible
- The tool performs updates row-by-row with WHERE clauses matching original values
- NULL values are preserved and not modified
GPL-2.0