# Bash

**Dependencies**

* `singlestore` client
* Bourne-Again Shell (`bash`)

**Code**

```shell
#!/bin/bash

MHOST="127.0.0.1"
MPORT="3306"
MUSER="root"
MDB=""
NUM_WORKERS=128
BATCH_SIZE=256

memsql_exec()
{
       singlestore -h $MHOST -P $MPORT -u $MUSER $MDB -e "$1"
}

memsql_exec_multi()
{
       singlestore -h $MHOST -P $MPORT -u $MUSER $MDB -e \
                "$(for ((b = 0; b < $BATCH_SIZE; b++)); do
                        echo "$1;"
                done)"
}

echo "Creating database test"
memsql_exec "CREATE DATABASE IF NOT EXISTS test"
MDB="test"

echo "Creating table tbl"
memsql_exec "CREATE TABLE IF NOT EXISTS tbl (id INT AUTO_INCREMENT PRIMARY KEY)"

echo "Launching $NUM_WORKERS workers"
sleep 1
declare -a WORKERS
for ((worker = 0; worker < $NUM_WORKERS; worker++)); do
        (while [ 1 ]; do
                echo "Worker $worker inserting"
                memsql_exec_multi "INSERT INTO tbl VALUES (NULL)"
        done) &
        WORKERS[$worker]=$!
done

sleep 10

for ((worker = 0; worker < $NUM_WORKERS; worker++)); do
        echo "Killing worker $worker"
        kill ${WORKERS[$worker]}
        wait ${WORKERS[$worker]} 2>/dev/null
done
echo "Cleaning up"
sleep 1
memsql_exec "DROP DATABASE test"

```

***

Modified at: May 14, 2026

Source: [/db/v9.1/developer-resources/concurrent-multi-insert-examples/bash/](https://docs.singlestore.com/db/v9.1/developer-resources/concurrent-multi-insert-examples/bash/)

(An index of the documentation is available at /llms.txt)
