mysql_inserter

Crates.iomysql_inserter
lib.rsmysql_inserter
version0.4.2
created_at2025-07-03 23:36:46.090752+00
updated_at2025-07-07 10:05:22.713464+00
descriptionPersonal usage MySQL executor.
homepage
repository
max_upload_size
id1737256
size88,086
Ji Younghyun (younghyun1)

documentation

README

How to Install and Run on macOS

1. Install Rust

Install Rust using the following command in your terminal:

brew install rust

After installation, check that Rust is correctly added to your environment variable (PATH).

2. Build the Project

Navigate to your project directory and run the following command to generate a release build:

cargo build --release

Once the build is completed, the executable file will be created at:

./target/release/mysql_inserter

3. Set Environment Variables

Prepare a .env file as shown below (be sure to assign values for each key):

DB_PORT=3306
DB_URL=localhost
DB_NAME=cci
DB_USER=root
DB_PW=
NUM_THREADS=8
TRANSACTION=true
  • NUM_THREADS: Number of MySQL connections (threads) to use concurrently.
  • TRANSACTION: Set to true if you want to process each SQL in a transaction block, otherwise set to false.

Note: You must explicitly specify the .env file when running the program. If not specified, an error will occur.

4. Run the Program

Execute the program in your terminal as follows:

./target/release/mysql_inserter <sql-dir> <dotenv-path>
  • <sql-dir>: Path to the directory containing the .sql files to execute.

  • <dotenv-path>: Full path to the .env file to use.

  • Example:

    ./target/release/mysql_inserter ./sqls ./myenv.env
    

5. How the Program Works

  1. Loads all .sql files in the specified directory into RAM (a progress bar will be displayed).
  2. Creates a MySQL connection pool using the DB info and thread count specified in the .env file.
  3. Before executing any SQL, displays key environment information (DB URL/USER/DB NAME, etc.) in the console along with a warning, and asks for your confirmation to proceed.
  4. Upon confirmation, executes the SQL files in parallel using multiple threads.
    • If TRANSACTION=true and a SQL script does not have a BEGIN~COMMIT block, a transaction wrapper will be automatically applied.
    • Successfully executed SQL files are moved into a newly created finished/ subfolder under the original folder.
    • Execution logs and errors for each file are saved to ./logs/transaction_YYYYMMDD_HHMMSS.log (structured JSON with detailed logs per file) and summarized/warned in the console.
  5. The overall progress (number of files being processed or completed) is shown in real-time with a progress bar.

6. Additional Information

  • SQL files that fail or encounter errors will remain in their original location and will not be moved.
  • Please ensure that, in case of simultaneous users or multiple workers, the same files are not processed concurrently (it is recommended to run only one instance per directory at a time).
  • Log files (./logs/) and successfully executed SQL files (in the finished/ directory) must be managed manually.

⚠️ Always double-check the scripts and perform a full backup before running this program on a critical database.

Commit count: 0

cargo fmt