How to Install MySQL 5.7 on Ubuntu 18.04 LTS

In this article, We are going to Perform How to install MySQL 5.7 on Ubuntu 18.04 LTS using command line.

Introduction

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.

#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 https://dev.mysql.com/get/mysql-apt-config_0.8.15-1_all.deb

Output:

https://dev.mysql.com/get/mysql-apt-config_0.8.15-1_all.deb

Resolving dev.mysql.com (dev.mysql.com)... 137.254.60.11

Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... connected.

HTTP request sent, awaiting response... 302 Found

Location: https://repo.mysql.com//mysql-apt-config_0.8.15-1_all.deb [following]

--2020-04-24 10:43:27--  https://repo.mysql.com//mysql-apt-config_0.8.15-1_all.deb

Resolving repo.mysql.com (repo.mysql.com)... 23.199.253.26

Connecting to repo.mysql.com (repo.mysql.com)|23.199.253.26|:443... connected.

HTTP request sent, awaiting response... 200 OK

Length: 35532 (35K) [application/x-debian-package]

Saving to: ‘mysql-apt-config_0.8.15-1_all.deb’

mysql-apt-config_0.8.15-1_all.deb         100%[=====================================================================================>]  34.70K  --.-KB/s    in 0.01s

2020-04-24 10:43:27 (2.71 MB/s) - ‘mysql-apt-config_0.8.15-1_all.deb’ saved [35532/35532]

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

sudo dpkg -i mysql-apt-config_0.8.15-1_all.deb

when we run above command like below prompt will open, By default it shows MySQL 8.0

configuring mysql apt

Click on First Option and Select MySQL 5.7 and Press Tab Button

select mysql 5.7 version

Press Tab Button and Enter

select mysql 5.7 and click on ok

#2: Update MySQL Repository

Update apt repository

sudo apt-get update

#3: Install MySQL 5.7 on Ubuntu 18.04 LTS

Install MySQL 5.7 using below commands,

sudo apt-get install mysql-server

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

mysql5.7confirmpassword

mysql-5.7password

#4: 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

 Success.
 All done!

#5: 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

Output:

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 4

Server version: 5.7.29 MySQL Community Server (GPL)

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

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

Now, We have successfully covered install MySQL 5.7 on Ubuntu 18.04 LTS.

#6: 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 'fosstechnix@123';

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'@'%';

OR

if you want to allow “fosstechnix” user  to give privileges to other user.

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

To take effect reload the privileges using below command,

mysql> FLUSH PRIVILEGES;

#7: How to Enable MySQL Remote Access in Ubuntu

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,

[mysqld]
bind-address  = 127.0.0.1

And replace it to

 bind-address = 0.0.0.0

Output:

How To Install MySQL 5.7 on Ubuntu 16.04 3

Restart the MySQL Server to take effect.

 sudo systemctl restart mysql.service

#8: 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

Conclusion:

In this article, We have performed ,How to Install MySQL 5.7 on Ubuntu 18.04 LTS System, creating new user and enabled remote access.

Related Articles:

How to Install MySQL 5.7 on Ubuntu 20.04 LTS

How to Install MySQL 8.0 on Ubuntu 18.04/16.04

How to Install MySQL 8 on CentOS 8

How to Install MariaDB on Ubuntu 18.04/16.04 LTS

Reference:

MySQL Official Documentation

FOSS TechNix

FOSS TechNix (Free,Open Source Software's and Technology Nix*) founded in 2019 is a community platform where you can find How-to Guides, articles for DevOps Tools,Linux and Databases.

Leave a Comment

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

Share via
Copy link
Powered by Social Snap