Install Mysql on Linux

How to install mysql in Linux – Ubuntu

Do you want to get a MySQL database up and running on Linux? So in this tutorial, we are going to walk through the process of installing MySQL database. The installing process is surprisingly easy the first thing we need to do is to get MySQL installed. Some systems might have the client installed but very few systems have the server installed by default.

The process for installing and managing my SQL is actually the same across red hat centos and Debian mint they all operate in the same manner. The only difference is going to be the commands to install the MySQL.

Command to Install on Debian Based Systems

sudo apt install mysql-server

Command to Install on Red Hat Centos or Fedora

sudo dnf install mysql-server

The above command going to install all of the MySQL software that we need. Hit yes when asked and it’s going to perform all the installation. The software is not terribly big the databases haven’t been made yet they’re what occupies all the space so it installs pretty quick. The MySQL database is targeted by hackers and malicious attackers regularly. So it’s super important that we secure it before we get it up and running to our network. To secure your database run a secure setup script with the command.

Command to secure MySQL server

sudo mysql_secure_installation

This is the same across all the Linux platforms. It’s very dangerous to deploy it without running this script. The first thing it’s going to ask is whether or not you want to validate for a password. Initially, it has a blank password for the root user by default obviously that’s bad so you have to validate the password component. Enter y or yes to set a password to validate component. Now choose the password strength according to your choice 0=>Low, 1=>Medium and 2=>Strong.

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: Y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG:


After that, you have to set up a new password for your Mysql root user. Enter any password of your choice and it asks you to enter again to make sure that it got it right.

Please set the password for root here.

New password: 

Re-enter new password: 

As we are using the Validate Password Plugin, we will receive feedback about the strength of our new password. If you satisfied with the strength of your password the Y to continue the script:

Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y

Then it offers to remove any anonymous users that default database has which can allow anonymous access to this database. So we don’t need any anonymous users select, yes to remove them. The next major thing we do is disallow root login remotely. It is a great idea the root user account really shouldn’t be used except for major administrative tasks. All the major root task can only or should only be performed locally not via the network. So a great way to stop people from taking advantage is disabling root login.

Delete the default test database for making a more secure path for your new work. Just enter yes to delete the test database and then lastly it’s going to reload the privilege table so it’s going to reload all the permissions since we just made some changes. Enter yes to allow that to happen. Once that’s done MySQL is now configured in a slightly more hardened fashion one that’s ready to be kind of put on the network and exposed out for regular use.

Now we could go ahead and turn it on startup when your system boots up. For starting it on boot type the below command

sudo systemctl enable --now mysql.service

All right sudo in command administrator privileges and then systemctl that’s how we interact with systems that manages all the background services. The enable means that we want to start when the system starts up — now means we want to start right now. Then that’s the service that powers the whole thing.  So now check whether the MySQL service is active/running or not by typing the below command.

systemctl status mysql.service

Technically we almost finished installing and running MySQL. But one extra step is we allow it through our firewall on ubuntu. For that enter the below command

sudo ufw allow MySQL

Now your server is up and running and people can get connected. So the process for installing MySQL is really not that hard we just need to install the package run the secure setup and then open the appropriate ports on the firewall.

Leave a Reply

Your email address will not be published. Required fields are marked *