Skip to content

Instantly share code, notes, and snippets.

@sheikhwaqas
Last active September 6, 2023 15:59
Show Gist options
  • Save sheikhwaqas/9088872 to your computer and use it in GitHub Desktop.
Save sheikhwaqas/9088872 to your computer and use it in GitHub Desktop.
Install MySQL Server on Ubuntu (Non-Interactive Installation)
# Download and Install the Latest Updates for the OS
apt-get update && apt-get upgrade -y
# Set the Server Timezone to CST
echo "America/Chicago" > /etc/timezone
dpkg-reconfigure -f noninteractive tzdata
# Enable Ubuntu Firewall and allow SSH & MySQL Ports
ufw enable
ufw allow 22
ufw allow 3306
# Install essential packages
apt-get -y install zsh htop
# Install MySQL Server in a Non-Interactive mode. Default root password will be "root"
echo "mysql-server-5.6 mysql-server/root_password password root" | sudo debconf-set-selections
echo "mysql-server-5.6 mysql-server/root_password_again password root" | sudo debconf-set-selections
apt-get -y install mysql-server-5.6
# Run the MySQL Secure Installation wizard
mysql_secure_installation
sed -i 's/127\.0\.0\.1/0\.0\.0\.0/g' /etc/mysql/my.cnf
mysql -uroot -p -e 'USE mysql; UPDATE `user` SET `Host`="%" WHERE `User`="root" AND `Host`="localhost"; DELETE FROM `user` WHERE `Host` != "%" AND `User`="root"; FLUSH PRIVILEGES;'
service mysql restart
@grzegorznowak
Copy link

hey, any example for installing mysql8 Non-Interactive Installation over ubuntu 18.8. ??

Yeah we've been looking for that as well @fcarrero and fortunately there's a sample that almost works out of the box, that I found literally yesterday evening and have folded it out a bit more since then:

https://geert.vanderkelen.org/2018/mysql8-unattended-dpkg/

For our molecule automation we've assembled Ubuntu Bionic working-confirmed version of that into:

https://github.com/spottmedia/shareable-ansible-toolkit/tree/master

And for completeness the crucial bit that did make it go over the line on Ubuntu was proper GPG key registration that the original wasn't coming through with (probably due to software-abrasive passage of time), see:

https://github.com/spottmedia/shareable-ansible-toolkit/blob/master/roles/dev-mysql8/tasks/main.yml

the rest is smart usage of debconf that Geert figured out there.

@sheikhwaqas
Copy link
Author

hey, any example for installing mysql8 Non-Interactive Installation over ubuntu 18.8. ??

Hey @fcarrero, I haven't tested MySQL 8 with Ubuntu 18.8 yet. But as soon as I do, there will definitely be either a new gist coming or will update this to take care of both installations :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment