MySQL is a popular Open Source Relational Database System aka RDBMS. MySQL uses a relational database & structured query language (SQL) to manage all the data. It’s used for developing all sorts of web-based applications.

It’s one of the most widely used database servers in the world & also the main component of the LAMP stack. In this tutorial, we will learn how we can install MySQL on Ubuntu.

Recommended Read: Simple guide to install POSTGRESQL on Ubuntu

Also Read: How to setup SSH login without password on Linux systems


Install MySQL on Ubuntu

Installation of MySql is fairly simple as the mysql packages are available with the default Ubuntu repositories. In order to install Mysql on Ubuntu, we only have run the following command from the terminal,

$ sudo apt-get update && sudo apt-get upgrade -y

$ sudo apt-get install mysql-server

Once the installation starts, we will be asked to enter a root password for MySQL. Enter a password and remember it as it will be required after installation, for configuration of mysql as well,

install mysql on ubuntu

Once the mysql has been installed, we need not start the mysql service as its started by default but we can check to make sure that its up & running by executing the following command,

$ sudo systemctl status mysql

Commands to start, stop & restart mysql service are,

$ sudo systemctl start mysql

$ sudo systemctl stop mysql

$ sudo systemctl restart mysql


Configuring MySQL

Next step after installing mysql is to secure the mysql installation, run the following command from the terminal,

$ sudo secure_mysql_installation

We will now be required to secure the installation of mysql by answering the following questions. To answer the questions positively. Press ‘Y’ or we can press any other key from the keyboard to answer in the negative,

1- Do we need to have a password policy for users accessing the DB. This is done with VALIDATE PASSWORD PLUGIN. If yes, what level of password policy & what should be the strength of password,

2- Remove anonymous users

3- Disallow root login remotely

4- Remove test database & its accessing

5- & lastly, Reload privileges table now.

install mysql on ubuntu

After completing the installation, we can now use the database. To connect to the database, run the following command from the terminal,

$ sudo mysql

Here we need to enter the root password that we created earlier during the installation of mysql. So that’s it, we now end our tutorial on how to install MySQL on Ubuntu. Please feel free to send in any questions or queries using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter | Linkedin

TheLinuxGURUS are thankful for your continued support.