How To Install MySQL on Ubuntu 18.04 /16.04

MySQL is an open-source database the executives framework, normally introduced as a major aspect of the well known LAMP (Linux, Apache, MySQL, PHP/Python/Perl) stack. It utilizes a social database and SQL (Structured Query Language) to deal with its information, visit official site –

In this post, We will install and configure MYSQL server on ubuntu 16.04 /18.04

Update Repository

Step 1:- Update repository by using following command.

$ sudo apt-get update

Step 2:- Install mysql-server using given command.

$ sudo apt-get install mysql-server -y

While installation of mysql-server, You will be asked for mysql root password, You need to type 2 time same password.

Step 3:- To get mysql service status use the following command.

$ sudo systemctl status mysql.service

Step 4:- Let’s secure mysql-server by using the mysql_secure_installation script, Which will removed un wanted things.

$ sudo mysql_secure_installation

While process the script, You need to put y to set password policy.

Securing the MySQL server deployment.

Enter password for user root:

VALIDATE PASSWORD PLUGIN 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 plugin?

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

Here you need to set number for LOW, MEDIUM, HARD.

Set this parameter according to you.

Estimated strength of the password: 25
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y

New password:

Re-enter new password:

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

By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Normally, root should only be allowed to connect from
‘localhost’. This ensures that someone cannot guess at
the root password from the network.

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
– Dropping test database…

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y

All done!

Step 5:- Login to mysql-shell using command-line.

$ mysql -u root -p


aftab@techbeginner:~$ mysql -u root -p
Enter password:

Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 20
Server version: 5.7.29-0ubuntu0.16.04.1 (Ubuntu)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective

Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the current input statement.


Step 6:- Configuration of the authentication method for MySQL users by using the command.

SELECT user,host,authentication_string,plugin FROM mysql.user;

ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘password’;


Authentication method for root is changed, by default mysql using port 3306, To confirm that use the given command below.

$ netstat -plntu | grep 3306

aftab@techbeginner:~$ netstat -plntu | grep 3306

(Not all processes could be identified, non-owned process info

will not be shown, you would have to be root to see it all.)

tcp 0 0* LISTEN –

How To Install MySQL on Ubuntu 18.04 /16.04

Leave a Reply

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

Scroll to top