By admin | July 13, 2016 | No Comments
MySQL is an open-source database management system, commonly installed as part of the popular LAMP(Linux, Apache, MySQL, PHP/Python/Perl) stack. It uses a relational database and SQL (Structured Query Language) to manage its data.
The short version of the installation is simple: update your package index, install the
mysql-serverpackage, and then run the included security and database initialization scripts.
This tutorial will explain how to install MySQL version 5.5, 5.6, or 5.7 on a Ubuntu 14.04 server. If you want more detail on these installation instructions, or if you want to install a specific version of MySQL, read on. However, if you’re looking to update an existing MySQL installation to version 5.7, you can read this MySQL 5.7 update guide instead.
To follow this tutorial, you will need:
There are two ways to install MySQL. You can either use one of the versions included in the APT package repository by default (which are 5.5 and 5.6), or you can install the latest version (currently 5.7) by manually adding MySQL’s repository first.
If you want to install a specific version of MySQL, follow the appropriate section below. To help you decide which version is best for you, you can read MySQL’s introduction to MySQL 5.5, then what’s new in MySQL 5.6 and what’s new in MySQL 5.7.
If you’re not sure, you can just use the
mysql-server APT package, which just installs the latest version for your Linux distribution. At the time of writing, that’s 5.5, but you can always update to another version later.
To install MySQL this way, update the package index on your server and install the package with
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. Move on to step two from here.
If you want to install MySQL 5.5 or 5.6 specifically, the process is still very straightforward. First, update the package index on your server.
Then, to install MySQL 5.5, install the
To install MySQL 5.6, install the
mysql-server-5.6 package instead.
For both options, 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.
If you want 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.
Next, install it using
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
Once the option says mysql-5.7, scroll down on the main menu to Apply and press
ENTER again. Now, update your package index.
Finally, install the
mysql-server package, which now contains MySQL 5.7.
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.
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.
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.
You’ll see some output like this:
mysql Ver 14.14 Distrib <span class="highlight">5.7.11</span>, 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
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.
This is due to some changes made in MySQL 5.6 and a minor error in the APT package.
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.
Regardless of how you installed it, MySQL should have started running automatically. To test this, check its 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 asroot (
-u root), prompt for a password (
-p), and return the 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 means MySQL is up and running.