How to Install MySQL in Ubuntu: A Step-by-Step Guide for 2024

Photo of author

Want to develop web-based software applications and websites? MySQL is your go-to option. It is one of the most popularly used open-source relational database management systems. It is a quick, easy, and scalable SQL-based system that is a crucial part of the LAMP stack that consists of Linux, Apache, MySQL, and PHP, which powers much of the Internet. This article will guide you on how to install MySQL on Ubuntu.

How to install MySQL on Ubuntu

How to install MySQL on Ubuntu

To have a working relational database for creating your websites and applications, you can install MySQL Version 8.0 on an Ubuntu 20.04 server. The steps are given below.

Step 1

To install MySQL, use the terminal prompt to execute the following command:

sudo apt update

Step 2

Enter your password, then wait while the update is complete. Run the subsequent command next:

sudo apt upgrade

Step 3

When asked to proceed with the upgrade, enter Y and click ENTER. After updating the package repository, you can proceed with installing MySQL.

Step 4

Enter the subsequent command to set up MySQL Server.

sudo apt install mysql-server

Step 5

If the system prompts you to continue the installation, select Y and press ENTER. The result should seem as follows:

step 5

Step 6

The MySQL Packages will then be downloaded by the system and installed on the computer of your choice.

Step 7

Run the following command to check whether MySQL was correctly set up.

mysql –version

Step 7

The version of MySQL installed on the machine is displayed in the output.

See also: How To Import A Large SQL File In XAMPP?

Configuring the MySQL installation 

After installation, your machine’s MySQL instance is already unsafe.

Step 1

To protect your MySQL user account with password authentication, run the security script that has been provided:

sudo mysql_secure_installation


Step 2

When prompted to continue configuring the VALIDATE PASSWORD component, enter your password and select Y. The component determines whether the new password is sufficiently secure.

Passwords must be at least eight characters long and have a combination of uppercase, lowercase, numeric, and special characters to qualify for the strictest policy level, which you can select by entering 2. The software then requests a confirmation password input from you twice. The password strength you choose for future MySQL users must match it.

Step 3

Press Y if the password meets your requirements. Choose another key if necessary.

Step 3

Step 4

The script then requests the following security features:

  • Take away the anonymous users?
  • Disallow remote root logins?
  • Take away access to the test database, and it?
  • Now reload the privilege tables.

Y is the suggested response to each of these queries. If you’d like a different option, enter any other key.

For instance, press any key other than Y at the prompt if you require the server’s remote login option.

Make that the MySQL service is up and functioning.

Once MySQL has been successfully installed, the MySQL service starts up immediately.

Step 5

Check to see if the MySQL service is

sudo systemctl status mysql

Step 5

The result should confirm that the service is active and running:

Logging into the MySQL server

Use the following command to log in to the MySQL interface:

sudo mysql -u root



What are the system requirements for installing MySQL in Ubuntu?

The system requirements for installing MySQL in Ubuntu include a minimum of 1 GB of RAM and around 1 GB of free disk space.

What is the default root password for MySQL in Ubuntu?

There is no default root password for MySQL in Ubuntu. During installation, you will get prompt to set a root password.

How can I start and stop the MySQL service in Ubuntu?

The MySQL service can start and stop in Ubuntu using the command 'sudo service mysql start' and 'sudo service mysql stop,' respectively.

How can I access the MySQL command line interface in Ubuntu?

The MySQL command line interface can be accessed in Ubuntu by typing 'MySQL -u root -p' and entering the root password.

What are some common MySQL commands?

Some common MySQL commands include 'CREATE DATABASE,' 'CREATE TABLE,' 'INSERT INTO,' 'SELECT,' and 'UPDATE.'

How can I create a new MySQL user in Ubuntu?

A new MySQL user can be created in Ubuntu using the command 'CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';'.


You may now use your new MySQL configuration to run queries, build databases, and test them. Check out our MySQL Commands Cheat Sheet to learn some crucial MySQL commands.

See also: Install conda on ubuntu

Leave a Comment