Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Completes an unattend installation of MySQL with phpMyAdmin.
# Author: Edwin Velez
# Author URI:
# Description: Completes an unattend installation of MySQL with phpMyAdmin.
# Update package index and upgrade existing packages
apt-get update
apt-get upgrade -y
# Install Debconf
apt-get install -y debconf-utils
# Disable prompts during installations
export DEBIAN_FRONTEND="noninteractive"
# Example Debconf usage to get selections: debconf-get-selections | grep mysql
# MySQL Server
debconf-set-selections <<< "mysql-server mysql-server/root_password password $MYSQL_PASSWORD"
debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $MYSQL_PASSWORD"
# phpMyAdmin
debconf-set-selections <<< "phpmyadmin phpmyadmin/reconfigure-webserver multiselect apache2"
debconf-set-selections <<< "phpmyadmin phpmyadmin/dbconfig-install boolean false"
debconf-set-selections <<< "phpmyadmin phpmyadmin/internal/skip-preseed boolean true"
# Download and install necessary packages
install_os_packages() {
apt-get install -y mysql-server phpmyadmin
# Secure mySql Installation
# See Assigning Anonymous Account Passwords (
secure_mysql_installation() {
# Remove anonymous logins.
`mysql -u root "-pPassword" mysql --execute="DROP USER ''@'localhost';"`
# Disallow root login remotely.
`mysql -u root "-pPassword" mysql --execute="DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '', '::1');"`
# Remove test database and access to it.
`mysql -u root "-pPassword" mysql --execute="DELETE FROM mysql.db WHERE Db LIKE 'test%';"`
`mysql -u root "-pPassword" mysql --execute="DROP DATABASE test;"`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.