Docs / Databases / How to Install MySQL on Ubuntu

How to Install MySQL on Ubuntu

By Admin · Feb 25, 2026 · Updated Apr 24, 2026 · 237 views · 1 min read

MySQL is the world's most popular open-source relational database.

Install

apt update
apt install mysql-server -y

Secure Installation

mysql_secure_installation

Follow the prompts to set a root password, remove anonymous users, disable remote root login, and remove the test database.

Connect

mysql -u root -p

Create a Database and User

CREATE DATABASE myapp;
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'SecurePassword123!';
GRANT ALL PRIVILEGES ON myapp.* TO 'myuser'@'localhost';
FLUSH PRIVILEGES;

Key Files

  • Config: /etc/mysql/mysql.conf.d/mysqld.cnf
  • Data: /var/lib/mysql/
  • Logs: /var/log/mysql/

Was this article helpful?