MySQL Getting Started
December 15, 2016
Step by Step Installing Linux, Apache, MySQL, PHP (LAMP) on Ubuntu 16.04
December 15, 2016

Easy Guidance How To Install MySQL on Ubuntu 14.04

MySQL is an the most popular open-source database management system, in most of hosting company its has been bundle by LAMP(Linux, Apache, MySQL, PHP/Python/Perl) stack. Another alternative variant of MySql is known as MariaDB

The installation is quite simple: update your package index, install the by execute in command prompt mysql-serverpackage.

  • sudo apt-get update
  • sudo apt-get install mysql-server
  • sudo mysql_secure_installation
  • sudo mysql_install_db


Installing MySQL


To install MySQL firstly update the package index on your server and install the package using apt-get.

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

Installing MySQL 5.5 or 5.6

If you need to install MySQL 5.5 or 5.6 specifically, the process is the same. First, update the package index on your server.

  • sudo apt-get update

Then, to install MySQL 5.5, install the mysql-server-5.5 package.

  • sudo apt-get install mysql-server-5.5

And you’ll be prompted to create a root password during the installation. Please choose a secure one and easy to remember.

Installing MySQL 5.7

To install MySQL 5.7, you’ll need to add the newer APT package repository from the MySQL APT repository page. Click Download on the bottom right, then copy the link on the next page from No thanks, just start my download. Download the .deb package to your server.

  • wget

Run the dpkg.

  • sudo dpkg -i mysql-apt-config_0.6.0-1_all.deb

You’ll see a prompt that asks you which MySQL product you want to configure. The MySQL Server option, which is highlighted, should say mysql-5.7. If it doesn’t, press ENTER, then scroll down to mysql-5.7 using the arrow keys, and press ENTER again.

Once the option says mysql-5.7, scroll down on the main menu to Apply and press ENTER again. Now, update your package index.

  • sudo apt-get update

Finally, install the mysql-server package, which now contains MySQL 5.7.

  • sudo apt-get install mysql-server

You’ll be prompted to create a root password during the installation. Choose a secure one and make sure you remember it, because you’ll need it later.

MySQL Configuration

First, you’ll want to run the included security script. This changes some of the less secure default options for things like remote root logins and sample users.

  • sudo mysql_secure_installation

This will prompt you for the root password you created in step one. You can press ENTER to accept the defaults for all the subsequent questions, with the exception of the one that asks if you’d like to change the root password. You just set it in step one, so you don’t have to change it now.

Next, we’ll initialize the MySQL data directory, which is where MySQL stores its data. How you do this depends on which version of MySQL you’re running. You can check your version of MySQL with the following command.

  • mysql –version

You’ll see some output like this:

mysql  Ver 14.14 Distrib 5.7.11, for Linux (x86_64) using  EditLine wrapper

If you’re using a version of MySQL earlier than 5.7.6, you should initialize the data directory by running mysql_install_db.

  • sudo mysql_install_db

Note: In MySQL 5.6, you might get an error that says FATAL ERROR: Could not find my-default.cnf. If you do, copy the /usr/share/my.cnf configuration file into the location that mysql_install_dbexpects, then rerun it.

  • sudo cp /etc/mysql/my.cnf /usr/share/mysql/my-default.cnf
  • sudo mysql_install_db

This is due to some changes made in MySQL 5.6 and a minor error in the APT package.


The mysql_install_db command is deprecated as of MySQL 5.7.6. If you’re using version 5.7.6 or later, you should use mysqld --initialize instead.

However, if you installed version 5.7 from the Debian distribution, like in step one, the data directory was initialized automatically, so you don’t have to do anything. If you try running the command anyway, you’ll see the following error:

2016-03-07T20:11:15.998193Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.

Check MySQL Status

Regardless of how you installed it, MySQL should have started running automatically. To test this, check its status.

  • service mysql status

You’ll see the following output (with a different PID).

mysql start/running, process 2689

If MySQL isn’t running, you can start it with sudo service mysql start.

For an additional check, you can try connecting to the database using the mysqladmin tool, which is a client that lets you run administrative commands. For example, this command says to connect to MySQL as root (-u root), prompt for a password (-p), and return the version.

  • mysqladmin -p -u root version

You should see output similar to this:

mysqladmin  Ver 8.42 Distrib 5.5.47, for debian-linux-gnu on x86_64
Copyright (c) 2000, 2015, 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.5.47-0ubuntu0.14.04.1
Protocol version    10
Connection      Localhost via UNIX socket
UNIX socket     /var/run/mysqld/mysqld.sock
Uptime:         4 min 15 sec

Threads: 1  Questions: 602  Slow queries: 0  Opens: 189  Flush tables: 1  Open tables: 41  Queries per second avg: 2.360

This indicated the MySQL is up and running now.