Files
weewx/bin/weedb/tests/setup_mysql
2020-12-17 15:45:34 -08:00

48 lines
2.3 KiB
Plaintext
Executable File

#/bin/bash
#
# Shell script to set up the MySQL database for testing
#
# It creates three users:
#
# 1. User: weewx
# Password: weewx
# 2. User: weewx1
# Password: weewx1
# 3. User: weewx2
# Password: weewx2
#
# NB: user weewx2 has more restrictive permissions than user weewx1
#
echo "You may get an error 'Operation DROP USER failed' when running this script."
echo "This can be safely ignored."
echo "Give the root password when prompted->"
mysql --force -u root -p << EOF
drop user 'weewx'@'localhost';
drop user 'weewx1'@'localhost';
drop user 'weewx2'@'localhost';
create user 'weewx'@'localhost' identified by 'weewx';
create user 'weewx1'@'localhost' identified by 'weewx1';
create user 'weewx2'@'localhost' identified by 'weewx2';
grant select, update, create, delete, drop, insert on test.* to 'weewx'@'localhost';
grant select, update, create, delete, drop, insert on test_alt_weewx.* to 'weewx'@'localhost';
grant select, update, create, delete, drop, insert on test_alt_weewx.* to 'weewx1'@'localhost';
grant select, update, create, delete, drop, insert on test_scratch.* to 'weewx'@'localhost';
grant select, update, create, delete, drop, insert on test_sim.* to 'weewx'@'localhost';
grant select, update, create, delete, drop, insert on test_sim.* to 'weewx1'@'localhost';
grant select, update, create, delete, drop, insert on test_weedb.* to 'weewx'@'localhost';
grant select, update, create, delete, drop, insert on test_weedb.* to 'weewx1'@'localhost';
grant select, update, create, delete, drop, insert on test_weewx.* to 'weewx'@'localhost';
grant select, update, create, delete, drop, insert on test_weewx.* to 'weewx1'@'localhost';
grant select, update, create, delete, drop, insert on test_weewx1.* to 'weewx'@'localhost';
grant select, update, create, delete, drop, insert on test_weewx2.* to 'weewx'@'localhost';
grant select, update, create, delete, drop, insert on test_weewx1.* to 'weewx1'@'localhost';
grant select, update, create, delete, drop, insert on test_weewx2.* to 'weewx1'@'localhost';
grant select, update, create, delete, drop, insert on test_weewx2.* to 'weewx2'@'localhost';
grant select, update, create, delete, drop, insert on weewx.* to 'weewx'@'localhost';
EOF
if [ $? -eq 0 ]; then
echo "Finished setting up MySQL."
else
echo "Problems setting up MySQL"
fi