dev-scripts/install/scripts/debian10/install-mysql.sh

37 lines
1.2 KiB
Bash
Raw Normal View History

2020-09-03 19:09:59 +00:00
#!/bin/sh
if [ "$mysql_version" != 'latest' ] ; then
echo 'ERROR: unable to install MySQL - only '"'latest'"' version currently supported'
exit 30
fi
# check we have ssh access
[ -z "$ssh_root" ] && echo "Error: no root ssh configuration specified" && exit 5
2020-09-03 19:09:59 +00:00
_mysql_cmd="mysql -uroot -e "
ssh -T $ssh_root << EOSSH
2020-09-03 19:09:59 +00:00
if mysql --version ; then
echo "ERROR: unable to install MySQL, 'mysql' already installed - aborting install"
exit 35
fi
echo "Installing MySQL"
export DEBIAN_FRONTEND=noninteractive
2020-09-04 21:24:19 +00:00
echo "Installing packages .."
apt-get install -qq -y mysql-server
echo "Packages installed"
2020-09-03 19:09:59 +00:00
$_mysql_cmd "DELETE FROM mysql.user WHERE User='';"
$_mysql_cmd "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');"
$_mysql_cmd "DROP DATABASE IF EXISTS test;"
$_mysql_cmd "DELETE FROM mysql.db WHERE Db='test' OR Db='"'test\\_%'"'"
2020-09-08 17:24:06 +00:00
$_mysql_cmd "CREATE DATABASE $db_name;"
$_mysql_cmd "GRANT ALL PRIVILEGES ON $db_name.* TO '$db_user'@'localhost' IDENTIFIED BY '$db_pass';"
$_mysql_cmd "FLUSH PRIVILEGES;"
2020-09-03 19:09:59 +00:00
mysqladmin --user=root password "$db_root_pass"
mysqladmin --user=root --password="$db_root_pass" flush-privileges
EOSSH