Install MySQL on Ubuntu


Step 1. Update package index

Execute the following command to update the local packages index with the latest changes made in the repositories:

sudo apt update

Step 2. Upgrade packages

Type the following command to upgrade the system:

sudo apt upgrade

Step 3. Configure MySQLPPA

MySQL provides an APT repository for install MySQL server and tools. You need to add this MySQL repository to your system’s package source list.

First, download the repository package using the wget command:

wget -c

Then, install the MySQL repository package using the following dpkg command:

sudo dpkg -i mysql-apt-config_0.8.13-1_all.deb

Step 4. Install MySQL

Execute the following command to start installing MySQL:

sudo apt-get install mysql-server

It will prompt for the root‘s password. Enter a secure password and continue.

Step 5. Secure MySQL server installation

Execute the following command to adjust security to the MySQL Server:

sudo mysql_secure_installation

It will prompt you some security options that you should choose in order to secure the MySQL server:

  • Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
  • Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
  • Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
  • Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y

Step 6. Manage MySQL Server via Systemd

Typically, MySQL service is automatically started once the package is configured. To check whether the MySQL server is up and running or not, you use this command:

sudo systemctl status mysql

If you found that the MySQL server does not automatically start, you can use the following command to start it:

sudo systemctl status mysql

And start it automatically at system startup:

sudo systemctl enable mysql

Step 7. Connect to MySQL server

To connect to the MySQL Server, use this command:

sudo mysql -u root -p

It will prompt for the password of the root account. You enter the password and press Enter, the following command will show if the password is valid:


Use the SHOW DATABASES to display all databases in the current server:

mysql> show databases;
| Database           |
| information_schema |
| mysql              |
| performance_schema |
| sys                |
4 rows in set (0.05 sec)
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Install MySQL

Note that if you use other operating system platforms such as Linux and macOS, you use the following tutorial: Install MySQL 8 on CentOS 7 Install MySQL 8 on Ubuntu Download MySQL Installer...

Install MySQL CentOS

To install MySQL 8 on CentOS 7, you follow these steps: Step 1. Setup Yum repository Execute the following command to enable MySQL yum repository on CentOS: rpm -Uvh...

How to Load the Sample Database into MySQL Server

Step 1 Download the classicmodels database from the MySQL sample database section. Step 2 Unzip the downloaded file into a temporary folder. You can use any folder you want. To make it simple,...

MySQL Sample Database

We use the classicmodels database as a MySQL sample database to help you work with MySQL quickly and effectively. The classicmodels database is a retailer of scale models of classic cars database....