Services Spotlight:

How to Install MySQL on an Ubuntu Server

Written By Corlew Solutions
Updated August 24, 2014
Published May 5, 2014
Why Corlew Solutions?

We write great software and provide amazing technical support. Contact us today if you need help with a software project:

  • Website: Send an inquiry
  • Email:

Article Technology Info

This article discusses the following technologies:

  • MySQL - Open Source database software.
    (website | download | docs)
  • mysql-server - Ubuntu package containing the MySQL Server and the MySQL command line tool

  • Ubuntu - A Debian-based Linux operating system that is a popular server choice.
    (website | download | wiki)

Installing MySQL on Ubuntu is a rite of passage for many budding server admins and software engineers. Almost every website needs a database on the server these days and MySQL is an excellent choice. This article covers how to install and setup MySQL server; we assume you only have little experience working with MySQL.

Let’s get started!

Install MySQL Server


Installing MySQL Server is exceedingly simple on Ubuntu; it is provided by the mysql-server package. If you look closely at the details of the package you will see that mysql-server is an empty package that depends on the mysql-server-5.5 package. Execute the following command and read the output to confirm for yourself:

sudo apt-cache show mysql-server

This structure allows people and other packages to refer to the general mysql-server package while letting the package maintainers determine which version of MysQL Server is the best in general. Let’s take a look and see if there any other versions of MySQL Server available to us:

sudo apt-cache search mysql-server

At the time this article was written, mysql-server-5.6 is also available in the repository. Therefore, we could install that package directly if we wanted mysql-server-5.6 instead.

With this information in mind, we are now ready to install MySQL Server on Ubuntu. Execute ONE of the following commands to start the installation.

sudo apt-get install mysql-server   # Install current approved version of mysql-server
sudo apt-get install mysql-server-5.5    # Install MySQL Server 5.5
sudo apt-get install mysql-server-5.6    # Install MySQL Server 5.6

Any of these commands will install a number of packages. In particular they will install mysql-client-x.x which will allow us to control the control MySQL Server from the command line via the mysql command.

Root Password

During the installation process you will be asked for a root password. This password helps maintain the security and integrity of your data so make sure you choose something very difficult.

Secure the Installation

Once the install has completed, run the following command to have mysql run the secure installation wizard:

sudo mysql_secure_installation

You will be asked a series of questions about your installation and you should take all of the recommendations provided by the wizard.

Create User and Database

If you already know the user and database you would like to create, you can execute the following couple of commands from the command line. First login to MySQL:

mysql -u root -p

Next, type the following commands while changing the appropriate values:

CREATE DATABASE exampledb;   # Creates a database named exampledb
CREATE USER 'exampleuser' IDENTIFIED BY 'examplepass';   # Creates exampleuser with password examplepass
GRANT ALL PRIVILEGES ON exampledb.* TO 'exampleuser';    # Grants all privileges to exampleuser
exit    # Exits mysql console

Graphical User Interface Options

You can login in the mysql console and perform almost all mysql commands via the command line. If you prefer working with a GUI, there are many tools available that will allow you to connect to your Ubuntu server via a method like SSH and then interact directly with your MySQL Server. Some options include: MySQL Workbench (free), SQL Yog (paid) and Heidi SQL (free).

We hope you found this article useful. If you see any mistakes, missing features or ways to improve it, please let us know in the comments below so we can update its contents. If you're willing to link to us, we would sincerely appreciate it!

Corlew Solutions is a Web Design and Web Application Development company based in Fairfax Virginia, minutes away Washington D.C. If you're looking for great web design from the Northern Virginia area or web design from the Washington D.C. area we can help. Contact Us today!

comments powered by Disqus