How to run mysql annoymise scripot from bash shell.
To anonymize the production database for using in the test environment, you can create a simple script that can run from the Linux Bash shell with a single command.
At first download a sample database:
# wget https://github.com/datacharmer/test_db/archive/master.zip
Next, unzip the file
# unzip master.zip
If zip is not already installed in your Linux box, use either “yum -y run zip” in RedHat or centos or run “apt-get -y install zip” for Debian based Linux Distribution.
# cd test_db-master
mysql -u root -p -h mytestdb.ccowcjsacvpb.eu-west-1.rds.amazonaws.com < employees.sql
once the upload is complete, you can create your anonymize script. The employees database has the following tables:
For example, you want to anonymize the title column in the titles table and the name and gender columns in the
employees table. Create a file called script.sql and past the following lines:
UPDATE employees.titles SET title=’DevOps’;
UPDATE employees.employees SET first_name=’Super’, last_name=’man’, gender=’F’;
Now run the script from the shell:
mysql -u root -p -h mytestdb.ccowcjsacvpb.eu-west-1.rds.amazonaws.com < script.sql
alternatively, you can run the script after logging into the MySQL shell:
mysql> source script.sql
Ref: https://oracle-base.com/articles/mysql/mysql-running-batch-scripts