mariadb.sh (1280B)
1 #!/usr/bin/env bash 2 3 set -o errexit 4 set -o nounset 5 set -o xtrace 6 7 # install mariadb server and tools 8 apt-get install -y mariadb-server mariadb-backup 9 10 # MySql secure install 11 # https://github.com/MariaDB/server/blob/main/scripts/mysql_secure_installation.sh 12 # 13 # Enter current password for root (enter for none) 14 # Switch to unix_socket authentication (y) 15 # New root password (twice) 16 # Remove anonymous users? (y) 17 # Disallow root login remotely? (y) 18 # Remove test database and access to it? (y) 19 # Reload privilege tables now? (y) 20 21 mariadb-secure-installation <<EOF 22 23 y 24 $MYSQL_ROOT_PASSWORD 25 $MYSQL_ROOT_PASSWORD 26 y 27 y 28 y 29 y 30 EOF 31 32 # configure .my.cnf for root 33 cat << EOF > /root/.my.cnf 34 [client] 35 user = root 36 password = $MYSQL_ROOT_PASSWORD 37 EOF 38 39 # add additional users 40 users=($MYSQL_ADDITIONAL_USERS) 41 hosts=($MYSQL_ADDITIONAL_HOSTS) 42 passwords=($MYSQL_ADDITIONAL_PASSWORDS) 43 no_users="${#users[@]}" 44 for ((i = 0 ; i < $no_users ; i++)); do 45 mysql -e "CREATE USER '${users[$i]}'@'${hosts[$i]}' IDENTIFIED BY '${passwords[$i]}';" 46 done; 47 48 # bind 49 #IP_ETH0=$(ip route | grep eth0 | grep src | awk '{print $9}') 50 #HOSTNAME=LXCNAME works as well, but refers to the container that was built last (nslookup LXCNAME) 51 sed -i "s/\(bind.*\) 127.0.0.1/\1 $MYSQL_BIND/g" /etc/mysql/mariadb.conf.d/50-server.cnf