Skip to content
Runbook

Install MySQL on Ubuntu / Debian

Popular open source SQL relational database.

Databasesqlrdbmsrelationaldatabaseacid

Installation

Server (Ubuntu repositories) · apt
sudo apt update
sudo apt install -y mysql-server

Ubuntu's main repository provides Oracle MySQL Server.

Verify the installation

Verify
mysql --version

Service

Start
sudo systemctl start mysql
Stop
sudo systemctl stop mysql
Status
sudo systemctl status mysql
Restart
sudo systemctl restart mysql
On boot
sudo systemctl enable mysql

Important files

TypePathDescription
config/etc/mysql/my.cnfTop-level configuration (includes mysql.conf.d and conf.d).
data/var/lib/mysqlData directory.
log/var/log/mysql/error.logServer error log.

Default ports

3306

Command-line tools

  • mysqlInteractive SQL client.
  • mysqladminAdministrative client.
  • mysql_secure_installationHardening script for the installation.

Uninstall

Uninstall
sudo apt purge -y 'mysql-server*' mysql-client
sudo apt autoremove -y

The /var/lib/mysql data directory remains; delete it manually to wipe everything.

Good to know

  • Run sudo mysql_secure_installation after install to set the root password and apply secure defaults.
  • The default root account uses auth_socket: connect with sudo mysql, then switch to a password if needed.
  • Debian (unlike Ubuntu) ships MariaDB under the mysql name; this guide targets Ubuntu's Oracle MySQL.

Installation on Ubuntu

sudo apt install -y mysql-server installs Oracle MySQL from Ubuntu's main repository and registers the mysql systemd service, started automatically. Verify with mysql --version.

Securing and first connection

By default the root account authenticates via the auth_socket plugin: connect as the system root with sudo mysql. Run sudo mysql_secure_installation to set passwords and remove insecure defaults. To use a password for root, switch its plugin to mysql_native_password from a SQL prompt.

Files and logs

The configuration entry point is /etc/mysql/my.cnf (which includes mysql.conf.d and conf.d); data lives in /var/lib/mysql and errors are logged to /var/log/mysql/error.log.