How To Install MySQL 5.7 on Ubuntu 16.04

In this article, we are going to demonstrate how to install MySQL 5.7 on Ubuntu 16.04 using command line.


MySQL is the world’s most popular open source relational database management system. It is widely used with web server like apache2,Nginx,IIS,etc.

MySQL has client/Server architecture , supports InnoDB storage engine,can be installed on various operating system like Ubuntu,Debian,CentOS,Windows.,etc.

Step 1: Add MySQL APT Repository in Ubuntu

Ubuntu comes with default package repositories. So,if we want to add/install latest repositories then we have to add/install package repositories.

Below are commands to add/download latest MySQL APT repository using command line,

$ sudo wget


--2019-03-23 17:31:39--
Resolving (…
Connecting to (||:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 35950 (35K) [application/x-debian-package]
Saving to: ‘mysql-apt-config_0.8.9-1_all.deb’
mysql-apt-config_0.8.9-1_all.deb 100%[===================================================================================>] 35.11K --.-KB/s in 0.01s
2019-03-23 17:31:40 (2.40 MB/s) - ‘mysql-apt-config_0.8.9-1_all.deb’ saved [35950/35950]

then, below command is to install above downloaded apt repository,

$ sudo dpkg -i mysql-apt-config_0.8.9-1_all.deb

when we run above command like below prompt will open, click on Ok.


Step 2: Update MySQL Repository and Install MySQL 5.7 on Ubuntu

Using above commands , we have downloaded apt repository and installed.

Next we have to update apt repository and install MySQL 5.7 using below commands,

$ sudo apt-get update
$ sudo apt-get install mysql-server

Now, Installation process will prompt default password for root user and again same password.

How To Install MySQL 5.7 on Ubuntu 16.04 1
How To Install MySQL 5.7 on Ubuntu 16.04 2

Step 3: Secure MySQL Installation

MySQL Server comes with a script mysql_secure_installation this can do multiple security related operations,

Run the below script on command prompt, asks below options.

$ mysql_secure_installation

Securing the MySQL server deployment.
Enter password for user root:
Would you like to setup VALIDATE PASSWORD plugin?
Press y|Y for Yes, any other key for No: No

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

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

All done!

Step 4: Login to MySQL

Now, Login to MySQL 5.7 Server using below command and use password to login entered during installation.

$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.25 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, 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.
Now, We have successfully installed MySQL 5.7 Database  on your Ubuntu server.

Step 5: Create MySQL Remote User

First, Login to MySQL Server with root user using command line, Below is command is to create user , here i am creating user “fosstechnix“.

mysql> CREATE USER 'fosstechnix'@'%' IDENTIFIED BY '[email protected]';

Next, assign the privileges to database with below command , here i am assigning all databases privileges to user fosstechnix,

If you want to assign privileges to specific database replace ” .” with database name.

mysql> GRANT ALL PRIVILEGES ON * . * TO 'fosstechnix'@'%';

To take effect reload the privileges using below command,


Step 6: How to Enable MySQL Remote Access in Ubuntu 16.04

By default, In MySQL database server remote access is disabled for security reason.

To enable remote connections of MySQL Server, we have to change bind-address in MySQL configuration file.

Open the /etc/mysql/mysql.conf.d/mysqld.cnf file

sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf  

Below the [mysqld] section find the Line,

bind-address =

And replace it to

 bind-address = 


How To Install MySQL 5.7 on Ubuntu 16.04 3

Restart the MySQL Server to take effect.

 $ sudo systemctl restart mysql.service

Step 7: Start/Restart/Stop MySQL Server Using Command Line

Below are commands to start/restart/stop MySQL 5.7 on Ubuntu 16.04

$ sudo systemctl start mysql.service 
$ sudo systemctl restart mysql.service
$ sudo systemctl stop mysql.service

Related Articles:

How to Install MySQL 8.0 on Ubuntu 18.04/16.04

4 thoughts on “How To Install MySQL 5.7 on Ubuntu 16.04”

  1. Wow, the tutorial was explanatory and crisp. Although, I am not a SQL guy, but I have used Ubuntu for almost an year in past. It took me sometime to understand Ubuntu as almost everything was too technical. Adding sudo 🙂

    But, I used to love it using Ubuntu. Great platform for free.

    Thanks Shivdas!

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe To Our Newsletter

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

We promise not to spam you, and we don't usually send more than one email a week.


You have Successfully Subscribed!

Share via
Copy link