Skip to content

Instantly share code, notes, and snippets.

@Udara-Dananjaya
Last active August 15, 2023 13:06
Show Gist options
  • Save Udara-Dananjaya/0db00b9050e07685e9fee5be9aca71fa to your computer and use it in GitHub Desktop.
Save Udara-Dananjaya/0db00b9050e07685e9fee5be9aca71fa to your computer and use it in GitHub Desktop.
Automate MySQL installation on Ubuntu: Update, clear rules, install MySQL Server, configure, and create a user with privileges.
# Install MySQL Server on Ubuntu
# Gain superuser privileges
sudo -i
# Define firewall rule for specified port
# Subnet > Ingress Rule > Source CIDR > 0.0.0.0/0
# TCP PORTS :3306
# Update the list of available software packages
sudo apt update -y
# Upgrade installed packages to their latest versions
sudo apt-get upgrade -y
sudo apt-get full-upgrade -y
# Clear existing iptables rules
sudo iptables -P INPUT ACCEPT
sudo iptables -P OUTPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
sudo iptables -F
# Install MySQL Server and MySQL Client
sudo apt install mysql-server mysql-client
# Edit MySQL configuration file
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
# Comment the line: bind-address = 127.0.0.1
# Restart MySQL Server
sudo systemctl restart mysql
# Access MySQL as root
sudo -i
mysql -u 'root' -h 'localhost' -p
# Create a new user, grant privileges, and flush privileges
CREATE USER 'dbadmin'@'%' IDENTIFIED BY 'dbadmin';
GRANT ALL PRIVILEGES ON *.* TO 'dbadmin'@'%';
FLUSH PRIVILEGES;
quit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment