A local application needs a place to store its data. MySQL Server is a database service that stores structured data and answers SQL requests, and the mysql client connects to it.
I’ll show you how to install the distribution package with APT and check whether the service is active.
TL;DR: Install MySQL with APT
On Ubuntu, install the server from the distribution repository with APT, then connect locally with the system administrator account.
sudo apt update
sudo apt install mysql-server
sudo systemctl status mysql
sudo mysql
APT selects a package from the enabled repositories, so the candidate can differ between Debian and Ubuntu releases. Check the release and candidate before relying on a version-specific recipe.
- Use the distribution package for a standard installation.
- On Ubuntu, the local root account commonly uses socket authentication, so start with sudo mysql rather than guessing a password.
- Create a separate database account for an application instead of using root.
What Is MySQL Server on Debian and Ubuntu?
MySQL Server is a database service that stores structured data and answers SQL requests. The mysql command-line client connects to it, while the mysql-server package installs the service.
MySQL Server runs as a database service and answers SQL requests. The MariaDB installation guide covers a separate server with a similar client command.
Oracle’s APT repository offers MySQL release-series selection and additional components, with package replacement described in its official setup guide.
MySQL and MariaDB share client commands, but replacing one server with the other is a migration. Identify the installed server and preserve a restorable backup before changing package sources.
Both systems use APT, but the release name and enabled sources determine the available version. Check the operating-system release first. Then inspect the candidate package before following release-specific instructions.
A working client does not prove the server is active or that an account can reach its database. Check the service and the account separately if an application cannot connect.
A storage engine controls how MySQL stores and works with table data. InnoDB is MySQL’s standard transactional engine. It supports transactions and foreign-key relationships.
Older guides may mention MyISAM, which does not support transactions. InnoDB does support transactions and foreign-key relationships. Choose an engine to match the application’s data needs, rather than changing the server package during a basic installation.
After connecting, inspect the server version and default engine from the MySQL shell. These read-only checks help confirm which server answered and which engine new tables will use.
How to Install MySQL on Debian or Ubuntu Step by Step
Install the distribution’s mysql-server package, check the service, then use the authentication method configured for the local root account. The command sequence below is for a system where you have a sudo-capable account and intend to install the repository’s default MySQL version.
- A Debian or Ubuntu system with a working APT repository configuration.
- A user account allowed to run administrative commands with sudo.
- A plan to use the distribution package, rather than Oracle’s alternate repository.
Step 1: Refresh the package index
Update APT’s local package lists before installing, so it resolves package names and versions from current repository metadata. This updates the index, not every installed package.
sudo apt update
Read any repository errors before moving on. If an entry is unavailable or its signature cannot be verified, fix that repository configuration rather than treating an old package list as current.
You can inspect the release and the package candidate with APT’s read-only package information tools. These checks do not install or change packages.
Step 2: Install the MySQL server package
Install the mysql-server package selected for your release. APT resolves its dependencies and asks for confirmation before changing the package state.
sudo apt install mysql-server
Installing the package requires administrative privileges and changes the package state. Inspect the available package candidate without installing it:
apt-cache policy mysql-server
mysql-server:
Installed: (none)
Candidate: 8.0.46-0ubuntu0.24.04.4
Version table:
8.0.46-0ubuntu0.24.04.4 500
500 http://ap-mumbai-1-ad-1.clouds.ports.ubuntu.com/ubuntu-ports noble-updates/main arm64 Packages
500 http://ports.ubuntu.com/ubuntu-ports noble-security/main arm64 Packages
8.0.36-2ubuntu3 500
500 http://ap-mumbai-1-ad-1.clouds.ports.ubuntu.com/ubuntu-ports noble/main arm64 Packages
Ubuntu’s official instructions say the server starts after installation. Package versions vary by release, so check the installed client version instead of copying a version number from a guide for a different Ubuntu or Debian release.
Step 3: Check the service and client
Check the client version after installation. The output identifies which client command is present, while a separate service-status check tells you whether the database server is active.
mysql --version
On this checked system, the command returned the MariaDB client, not Oracle MySQL:
mysql Ver 15.1 Distrib 10.11.14-MariaDB, for debian-linux-gnu (aarch64) using EditLine wrapper

The version output identifies the client build, not the server package. Check service state with systemctl status mysql on your installed system. If the unit is inactive, inspect its logs before changing configuration.
For background on managing Linux services, see how to start, stop, and restart services.
Step 4: Open the local MySQL shell
Ubuntu documents local socket authentication for the MySQL root account. Open the administrative shell through the Unix socket:
sudo mysql
At the mysql> prompt, the client is connected to the server. Type exit to leave the database shell. Debian authentication defaults vary by package source and release, so consult that package’s documentation if the command is rejected.
Step 5: Create a database and a dedicated account
Create an application account scoped to its database instead of using the administrator account. In the MySQL shell, replace the example names and password with values you choose, then store the password securely.
CREATE DATABASE appdb;
CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'replace-with-a-strong-password';
GRANT ALL PRIVILEGES ON appdb.* TO 'appuser'@'localhost';
SHOW GRANTS FOR 'appuser'@'localhost';
See the MySQL user and permissions guide for other privilege scopes.
For a backup workflow, see the guide to backing up MySQL databases.
What If MySQL Does Not Start or Root Login Fails?
Check the service state before investigating an account login.
| Symptom | What to check | Next step |
|---|---|---|
| mysql.service is inactive | Service status and journal | Review the reported startup error before attempting a restart. |
| mysql: command not found | Whether mysql-client or server packages installed | Check APT package state for this release and install the needed client package. |
| Access denied for root with -p | Authentication plugin and selected package source | On Ubuntu’s default setup, try local socket login with sudo mysql. |
| Application connection fails | Database name, account host, password and grants | Use the dedicated app account and verify its database-scoped grants. |
When mysql.service stays inactive, use sudo journalctl -u mysql to read the startup log and locate the service error. For an account login failure, check the authentication plugin and grants before considering package changes.
The mysql_secure_installation utility offers security choices such as removing anonymous accounts and remote root accounts. Its prompts depend on the server build and configuration, so read each one before confirming an action.
Keep network access disabled for a local installation. Enable it only when an application needs remote connections.
A MySQL account includes a host component: appuser at localhost is a local database identity, separate from a Linux login with the same name.
A wildcard host broadens where an account can connect from, so the example keeps localhost for local connections.
For an existing installation, consult the vendor’s replacement guidance before changing repositories.
Conclusion: Use the Distribution Package First
After installation, verify the service and use the local authentication method configured by the package. Create a database-scoped account for each application.
For package-specific behavior, use the Ubuntu MySQL server documentation or the MySQL APT repository guide.
FAQ
These quick answers cover the first checks after installation.
How do I check if MySQL is installed on Ubuntu?
Run mysql –version to check the client, and sudo systemctl status mysql to check whether the server service is active.
Why does sudo mysql work when mysql -u root -p does not?
Ubuntu’s default MySQL root account uses local socket authentication. sudo mysql connects through the local socket using operating-system administrative access rather than a MySQL root password.
Should I add the MySQL APT repository?
Use the distribution repository for a standard installation. Add Oracle’s MySQL APT repository when you specifically need a release series or component it supplies, and follow its official setup and replacement instructions.
