This page provides a practical baseline setup for MySQL on Linux hosts with current best practices for DevOps environments.
# Update package index
sudo apt update
# Install MySQL server (includes client, common files)
sudo apt install -y mysql-server
# Check service status
sudo systemctl status mysql
# Download and install MySQL APT repository configuration package
wget https://dev.mysql.com/get/mysql-apt-config_0.8.24-1_all.deb
sudo dpkg -i mysql-apt-config_0.8.24-1_all.deb
# Update package index
sudo apt update
# Install MySQL server
sudo apt install -y mysql-server
# During installation, you may be prompted for:
# - Root password setup method (recommended: use strong password)
# - Default authentication plugin (recommended: Use Strong Password Encryption)
# Update package index
sudo dnf update -y
# Install MySQL server
sudo dnf install -y mysql-server
# Check service status
sudo systemctl status mysqld
# Download and install MySQL YUM repository configuration package
sudo rpm -Uvh https://dev.mysql.com/get/mysql84-community-release-el9-1.noarch.rpm
# Update package index
sudo dnf update -y
# Install MySQL server
sudo dnf install -y mysql-community-server
# Check service status
sudo systemctl status mysqld
# Enable service to start at boot
sudo systemctl enable mysql # On Debian/Ubuntu
sudo systemctl enable mysqld # On RHEL-family
# Start service immediately
sudo systemctl start mysql # On Debian/Ubuntu
sudo systemctl start mysqld # On RHEL-family
# Check service status
sudo systemctl status mysql # On Debian/Ubuntu
sudo systemctl status mysqld # On RHEL-family
After installation, run the security script to improve MySQL’s security:
sudo mysql_secure_installation
This script will guide you through:
# Check MySQL version
mysql --version
# Connect to MySQL (may require initial password setup)
sudo mysql -e "SELECT VERSION();"
# Check MySQL service status
sudo mysql -e "SHOW STATUS LIKE 'Uptime';"
# Check MySQL configuration files
sudo mysql -e "SHOW VARIABLES LIKE 'config%';"
# View current user accounts
sudo mysql -e "SELECT User, Host FROM mysql.user;"
# Check current connections
sudo mysql -e "SHOW PROCESSLIST;"
/etc/mysql/mysql.conf.d/mysqld.cnf/etc/my.cnf, /etc/mysql/my.cnf, or /usr/my.cnfmysql_secure_installation and enforce private network access