Skip to content

Instantly share code, notes, and snippets.

@fahadsiddiqui
Created May 12, 2020 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fahadsiddiqui/f3d5840dc1b3c9ca5829b1bdb430ce8e to your computer and use it in GitHub Desktop.
Save fahadsiddiqui/f3d5840dc1b3c9ca5829b1bdb430ce8e to your computer and use it in GitHub Desktop.
Preparing test docker-ized mysql database.

First of all generate the data, here is an interesting tool to do that https://pypi.org/project/csvfaker/

Create test_data/ folder and use csvfaker to put data in there

csvfaker -r 100000 first_name last_name email ssn job country phone_number user_name zipcode invalid_ssn credit_card_number credit_card_provider credit_card_security_code bban > test_data/pii_data.csv

Then create a docker container using image mysql:5.7 and mount volume test_data/

docker run --name mysql_test_db -v /Users/fahad/test_data:/data -e MYSQL_ROOT_PASSWORD=root -p "9099:3306" -d mysql:5.7

exec into container and create database / table

# go inside container
docker exec -it mysql_test_db bash

# create db / table
root@b7b888b959e6:/# mysql -uroot -p
Enter password:

mysql> CREATE DATABASE ptest_db;
mysql> USE ptest_db;
mysql> CREATE TABLE pii_data( 
		first_name VARCHAR(400),
		last_name VARCHAR(400),
		email VARCHAR(400),
		ssn VARCHAR(400),
		job VARCHAR(400),
		country VARCHAR(400),
		phone_number VARCHAR(400),
		user_name VARCHAR(400),
		zipcode VARCHAR(400),
		invalid_ssn VARCHAR(400),
		credit_card_number VARCHAR(400),
		credit_card_provider VARCHAR(400),
		credit_card_security_code VARCHAR(400),
		bban VARCHAR(400));

Now go to docker container / and run following.

mysqlimport --ignore-lines=1 \
            --fields-terminated-by=, \
            --fields-optionally-enclosed-by=\" \
            --fields-escaped-by=\\ \
            --local -u root \
            -p ptest_db \
            data/pii_data.csv

The data is hosted in your db / table.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment