Tutorial

How To Install the Latest MySQL on Debian 9

Published on September 5, 2018
English
How To Install the Latest MySQL on Debian 9
Not using Debian 9?Choose a different version or distribution.
Debian 9

Introduction

MySQL is a prominent open source database management system used to store and retrieve data for a wide variety of popular applications. MySQL is the M in the LAMP stack, a commonly used set of open source software that also includes Linux, the Apache web server, and the PHP programming language.

In Debian 9, MariaDB, a community fork of the MySQL project, is packaged as the default MySQL variant. While, MariaDB works well in most cases, if you need features found only in Oracle’s MySQL, you can install and use packages from a repository maintained by the MySQL developers.

To install the latest version of MySQL, we’ll add this repository, install the MySQL software itself, secure the install, and finally we’ll test that MySQL is running and responding to commands.

Prerequisites

Before starting this tutorial, you will need:

Step 1 — Adding the MySQL Software Repository

The MySQL developers provide a .deb package that handles configuring and installing the official MySQL software repositories. Once the repositories are set up, we’ll be able to use Ubuntu’s standard apt command to install the software. We’ll download this .deb file with wget and then install it with the dpkg command.

First, load the MySQL download page in your web browser. Find the Download button in the lower-right corner and click through to the next page. This page will prompt you to log in or sign up for an Oracle web account. We can skip that and instead look for the link that says No thanks, just start my download. Right-click the link and select Copy Link Address (this option may be worded differently, depending on your browser).

Now we’re going to download the file. On your server, move to a directory you can write to. Download the file using wget, remembering to paste the address you just copied in place of the highlighted portion below:

  1. cd /tmp
  2. wget https://dev.mysql.com/get/mysql-apt-config_0.8.10-1_all.deb

The file should now be downloaded in our current directory. List the files to make sure:

  1. ls

You should see the filename listed:

Output
mysql-apt-config_0.8.10-1_all.deb . . .

Now we’re ready to install:

  1. sudo dpkg -i mysql-apt-config*

dpkg is used to install, remove, and inspect .deb software packages. The -i flag indicates that we’d like to install from the specified file.

During the installation, you’ll be presented with a configuration screen where you can specify which version of MySQL you’d prefer, along with an option to install repositories for other MySQL-related tools. The defaults will add the repository information for the latest stable version of MySQL and nothing else. This is what we want, so use the down arrow to navigate to the Ok menu option and hit ENTER.

The package will now finish adding the repository. Refresh your apt package cache to make the new software packages available:

  1. sudo apt update

Now that we’ve added the MySQL repositories, we’re ready to install the actual MySQL server software. If you ever need to update the configuration of these repositories, just run sudo dpkg-reconfigure mysql-apt-config, select new options, and then sudo apt-get update to refresh your package cache.

Step 2 — Installing MySQL

Having added the repository and with our package cache freshly updated, we can now use apt to install the latest MySQL server package:

  1. sudo apt install mysql-server

apt will look at all available mysql-server packages and determine that the MySQL provided package is the newest and best candidate. It will then calculate package dependencies and ask you to approve the installation. Type y then ENTER. The software will install.

You will be asked to set a root password during the configuration phase of the installation. Choose and confirm a secure password to continue. Next, a prompt will appear asking for you to select a default authentication plugin. Read the display to understand the choices. If you are not sure, choosing Use Strong Password Encryption is safer.

MySQL should be installed and running now. Let’s check using systemctl:

  1. sudo systemctl status mysql
Output
● mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2018-09-05 15:58:21 UTC; 30s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Main PID: 12805 (mysqld) Status: "SERVER_OPERATING" CGroup: /system.slice/mysql.service └─12805 /usr/sbin/mysqld Sep 05 15:58:15 mysql1 systemd[1]: Starting MySQL Community Server... Sep 05 15:58:21 mysql1 systemd[1]: Started MySQL Community Server.

The Active: active (running) line means MySQL is installed and running. Now we’ll make the installation a little more secure.

Step 3 — Securing MySQL

MySQL comes with a command we can use to perform a few security-related updates on our new install. Let’s run it now:

  1. mysql_secure_installation

This will ask you for the MySQL root password that you set during installation. Type it in and press ENTER. Now we’ll answer a series of yes or no prompts. Let’s go through them:

First, we are asked about the validate password plugin, a plugin that can automatically enforce certain password strength rules for your MySQL users. Enabling this is a decision you’ll need to make based on your individual security needs. Type y and ENTER to enable it, or just hit ENTER to skip it. If enabled, you will also be prompted to choose a level from 0–2 for how strict the password validation will be. Choose a number and hit ENTER to continue.

Next you’ll be asked if you want to change the root password. Since we just created the password when we installed MySQL, we can safely skip this. Hit ENTER to continue without updating the password.

The rest of the prompts can be answered yes. You will be asked about removing the anonymous MySQL user, disallowing remote root login, removing the test database, and reloading privilege tables to ensure the previous changes take effect properly. These are all a good idea. Type y and hit ENTER for each.

The script will exit after all the prompts are answered. Now our MySQL installation is reasonably secured. Let’s test it again by running a client that connects to the server and returns some information.

Step 4 – Testing MySQL

mysqladmin is a command line administrative client for MySQL. We’ll use it to connect to the server and output some version and status information:

  1. mysqladmin -u root -p version

The -u root portion tells mysqladmin to log in as the MySQL root user, -p instructs the client to ask for a password, and version is the actual command we want to run.

The output will let us know what version of the MySQL server is running, its uptime, and some other status information:

Output
mysqladmin Ver 8.0.12 for Linux on x86_64 (MySQL Community Server - GPL) Copyright (c) 2000, 2018, 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 owners. Server version 8.0.12 Protocol version 10 Connection Localhost via UNIX socket UNIX socket /var/run/mysqld/mysqld.sock Uptime: 6 min 42 sec Threads: 2 Questions: 12 Slow queries: 0 Opens: 123 Flush tables: 2 Open tables: 99 Queries per second avg: 0.029

If you received similar output, congrats! You’ve successfully installed the latest MySQL server and secured it.

Conclusion

You’ve now completed a basic install of the latest version of MySQL, which should work for many popular applications.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors


Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
2 Comments


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

tank@debian-s-1vcpu-1gb-sfo2-02:/tmp$ sudo dpkg -i mysql-apt-config* Selecting previously unselected package mysql-apt-config. (Reading database … 30579 files and directories currently installed.) Preparing to unpack mysql-apt-config_0.8.10-1_all.deb … Unpacking mysql-apt-config (0.8.10-1) … Setting up mysql-apt-config (0.8.10-1) … Warning: apt-key should not be used in scripts (called from postinst maintainerscript of the package mysql-apt-config) key 8C718D3B5072E1F5: 75 signatures not checked due to missing keys OK

Awesome article!!! Thank you!!! I have installed MySQL 8.0.12 on Debian 9 with ease. It was awesome thanks.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more