Install MySQL on Ubuntu via sudo apt install mysql-server. The Ubuntu docs walk through the setup. Run mysql_secure_installation post-install to set root password, remove anonymous users, and disable remote root login. The team that uses the official mysql-server package (Ubuntu’s curated) has stability; the team that uses MySQL’s apt repo has the latest version.
Table of contents
- Install via apt
- Start the service
- mysql_secure_installation
- Create a database and user
- Allow remote connections
- Configure for production
- Test the install
- FAQ
Install via apt
sudo apt update
sudo apt install mysql-server
This installs MySQL 8.0 on Ubuntu 22.04, 8.0 or 8.4 on 24.04.
Start the service
sudo systemctl enable --now mysql
sudo systemctl status mysql
The team that enables the service has MySQL start at boot.
mysql_secure_installation
sudo mysql_secure_installation
This walks through:
- Set root password.
- Remove anonymous users.
- Disallow root login remotely.
- Remove test database.
- Reload privilege tables.
The team that runs this has hardened MySQL. The team that skips has anonymous users and weak root.
Create a database and user
sudo mysql
CREATE DATABASE myapp;
CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'strong_password';
GRANT ALL PRIVILEGES ON myapp.* TO 'appuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
The team that creates app-specific users has least-privilege. The team that uses root for everything has a security incident.
Allow remote connections
Edit /etc/mysql/mysql.conf.d/mysqld.cnf:
bind-address = 0.0.0.0 # or specific IP
Restart:
sudo systemctl restart mysql
Then CREATE USER 'appuser'@'%' IDENTIFIED BY 'pwd'; for remote. The team that opens remote access also opens 3306 in the firewall.
Configure for production
- Set
innodb_buffer_pool_sizeto ~50% of RAM. - Set
max_connectionsbased on workload (default 151). - Set
slow_query_log = 1for performance debugging. - Set
log_errorto a persistent location. - Backup: mysqldump + cron, or Percona XtraBackup for hot backups.
Test the install
sudo mysqladmin -u root -p version
Shows MySQL version. The team that verifies has working install.
FAQ
What’s the default MySQL user after install?
root, authenticated via auth_socket plugin (Ubuntu’s default - uses OS user, not password). The team that changes this for production has password auth.
How do I reset the root password?
sudo systemctl stop mysql
sudo mysqld --skip-grant-tables &
mysql -u root
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpwd';
Then restart. The team that has the recovery path can reset.
Can I install multiple MySQL versions?
Yes via Ubuntu’s mysql-X.Y packages or Docker. The team that tests across versions has multi-version setup.
Where are MySQL config files?
/etc/mysql/mysql.conf.d/mysqld.cnf (Ubuntu), /etc/my.cnf (RHEL). The team that edits these has full config control.
How do I enable slow query log?
SET GLOBAL slow_query_log = 'ON'; or in my.cnf: slow_query_log = 1, long_query_time = 2. The team that monitors slow queries has performance visibility.
If you are sizing the infrastructure for the kind of project this post covers, the RunxBuild hosting calculator is the right place to model the line items. The compute, the memory, the storage, the bandwidth, the database - each one is a separate number, and the team’s mental model for the platform is the sum of those numbers. The RunxBuild dashboard is where the team sees the actual usage in one place.
Useful related references: