How to Install MySQL Server on Ubuntu

install mariadb on ubuntu

MySQL is probably the most popular open source database server in used today. From hosting WordPress to Drupal and Joomla, MySQL might be used in all these environments.

This brief tutorial is going to show students and new users how to easily install MySQL server on Ubuntu 16.10.

When running WordPress, Drupal other content management systems, you’ll probably use MySQL database server. It’s an open source database server that is part of the LAMP stack used with most PHP based scripts.

Installing MySQL database server on Ubuntu is easy. Follow the steps below to learn how:

Step 1: Preparing the Ubuntu Server

Before installing packages on Ubuntu server, your first task will be to update the server. To do that, run the commands below.

sudo apt-get update && sudo apt-get dist-upgrade && sudo apt-get autoremove

Step 2: Installing MySQL

After updating your server, simply run the commands below to install MySQL from Ubuntu default package repository. You’ll install the latest version of MySQL server in the repository at that time.

sudo apt-get install mysql-server mysql-client

Ubuntu shows you the packages that are going to be installed and asks if you want to continue ?

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libaio1 libevent-core-2.0-5 libhtml-template-perl mysql-client-5.7
mysql-client-core-5.7 mysql-common mysql-server-5.7 mysql-server-core-5.7
Suggested packages:
libipc-sharedcache-perl mailx tinyca
The following NEW packages will be installed:
libaio1 libevent-core-2.0-5 libhtml-template-perl mysql-client
mysql-client-5.7 mysql-client-core-5.7 mysql-common mysql-server
mysql-server-5.7 mysql-server-core-5.7
0 upgraded, 10 newly installed, 0 to remove and 0 not upgraded.
Need to get 19.7 MB of archives.
After this operation, 170 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

When you run the commands above, you’ll be prompted to create a root password for MySQL. The password allows you to sign on to MySQL server and manage it.

Ubuntu MySQL password prompt screen

Step 3: Configuring MySQL

After installing MySQL, run the commands below to secure the database server. This script included with MySQL allows to change some of the less secure default settings for MySQL. This includes allowing remote root logins and removing MySQL test database.

Run the security script below

sudo mysql_secure_installation

When you run that, you’ll be prompted to answer series of security questions. Follow the guide below to secure MySQL

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

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

Now MySQL should be ready to use. To check the version installed, run the commands below

mysqladmin -u root -p version

Info like the one below are shown to you

mysqladmin Ver 8.42 Distrib 5.7.16, for Linux on x86_64
Copyright (c) 2000, 2016, 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

Server version 5.7.16-0ubuntu0.16.10.1
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/run/mysqld/mysqld.sock
Uptime: 3 min 10 sec

Threads: 1 Questions: 9 Slow queries: 0 Opens: 115 Flush tables: 1 Open tables: 34 Queries per second avg: 0.047

This is how to install and configure MySQL on Ubuntu 16.10

Other commands to remember:

Stop MySQL — > sudo systemctl stop mysql.service

Start MySQL –> sudo systemctl start mysql.service

Enable MySQL –> sudo systemctl enable mysql.service


Leave a Reply

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

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