#! /bin/bash

SERV=192.168.0.83
USR1=root
USR2=foobar
DB_TST=foo_db

echo
echo ===== OS
egrep '^NAME|PRETTY' /etc/os-release

echo
echo ===== MySQL software
rpm -qa | fgrep -i mysql | sort

echo
echo ===== errmsg.sys
find /usr -xdev -name errmsg.sys 2>/dev/null | xargs ls -ld

echo
echo ===== Set up test user + DB
mysql -h $SERV -u $USR1 --table 2>&1 <<eoc
    create user ${USR2}@'%' ;
    create database $DB_TST ;
    grant all privileges on ${DB_TST}.* to ${USR2}@'%' ;
    show grants for ${USR2}@'%' ;
    show databases ;
eoc

echo
echo ===== Run some commands that will produce error messages
mysql -h $SERV -u $USR2 -D $DB_TST --table --force -v 2>&1 <<eoc
    create table some_tab (
        id INT AUTO_INCREMENT,
        was VARCHAR(30),
        PRIMARY KEY (id) );
    show create table some_tab \G
    insert into some_tab (was) values ("The very first row");
    insert into some_tab (was) values ("Give it a companion");
    commit;
    -- correct
    select * from some_tab;
    -- will fail
    insert into some_tab (id, was) values (1, "Will not make it");
    show create table nonesuch ;
    drop table will_fail ;
eoc

echo
echo ===== Cleanup
mysql -h $SERV -u $USR1 --table 2>&1 <<eoc
    drop user ${USR2}@'%' ;
    drop database $DB_TST ;
    show grants for ${USR2}@'%' ;
    show databases ;
eoc
