MySQL 5.7 on Ubuntu 16.04
MySQL 5.7 on Ubuntu 16.04

MySQL is an open-source relational database management system. This tutorial will help you to install MySQL server on your Ubuntu and Debian systems. This version has various security improvements than the previous versions.

Step 1 – Configure Apt Repository

Download the MySQL apt configuration Debian package officially provided by the MySQL team and install it on your system. For Ubuntu 16.04 and later version’s MySQL 5.7 is available under default apt repositories, so you don’t need to enable additional repository that.

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

This will prompt you to select MySQL version to be install. So that the dpkg can configure the apt repository accordingly.

Step 2 – Install MySQL Server

Use the following commands to install MySQL server on your Ubuntu 16.04 and 14.04 systems. Currently, this is the most popular version used by among users.

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

The installation process will prompt the default password of the root user and again to confirm the password.

Step 3 – Secure MySQL Installation

Now run the mysql_secure_installation command. This will prompt for the configuration of variable security changes. Like enable password strength using VALIDATE PASSWORD PLUGIN, disable remote root login, remote test database and connection to it.


Follow onscreen instructions

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:
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) :

 ... skipping.
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

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...

 - Removing privileges on 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!

Recommended Reading:  How to Install PHP 7.3 on Ubuntu 16.04

Step 4 – Working with MySQL

Finally, log in to the MySQL server using the following command. Enter the password created during installation. Here you can create database and tables to store data. You can read our online MySQL tutorial to perform various tasks with the MySQL command line. You may also need to disable strict SQL mode.

mysql -u root -p

MySQL Command Prompt

Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.26 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.



Please enter your comment!
Please enter your name here