Tutorial

How To Install the Latest MySQL on Debian 10

How To Install the Latest MySQL on Debian 10
Not using Debian 10?Choose a different version or distribution.
Debian 10

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 10, 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.

In this tutorial, you will install the latest version of MySQL by adding this repository, install the MySQL software itself, secure the install, and test that MySQL is running and responding to commands.

Prerequisites

Before starting this tutorial, you will need one Debian 10 server that has a non-root user with sudo privileges and a firewall configured. You can do this by following our initial server setup guide for Debian 10.

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, you’ll be able to use Debian’s standard apt command to install the software.

Before doing this, you need to install the prerequisite GnuPG package, an open-source implementation of the OpenPGP standard.

Begin by updating the local package index to reflect the latest upstream changes:

  1. sudo apt update

Then, install the gnupg package:

  1. sudo apt install gnupg

After confirming the installation, APT will install gnupg and its dependencies.

Next, you’ll download the MySQL .deb package with wget and then install it using the dpkg command.

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. You can skip that and find 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 you’re going to download the file. On your server, move to a directory you can write to, such as the temporary /tmp directory used in this example:

  1. cd /tmp

Next, download the file using wget, remembering to paste the address you copied in place of the highlighted portion in the following command:

  1. wget https://dev.mysql.com/get/mysql-apt-config_0.8.22-1_all.deb

The file should now be downloaded in your current directory. List the files to confirm:

  1. ls

The output will return a list of various files, including the one you just downloaded, which is highlighted in the following example:

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

Now you’re ready for installation. Run the dpkg command which is used to install, remove, and inspect .deb software packages. The -i flag indicates that you’d like to install from the specified file:

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

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 will choose for our purposes, 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 you’ve added the MySQL repositories, you’re ready to install the actual MySQL server software. If you ever need to update the configuration of these repositories, 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 your package cache freshly updated, now you can use apt to install the latest MySQL server package:

  1. sudo apt install mysql-server

apt will scan 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. Write 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 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. Check by using systemctl:

  1. sudo systemctl status mysql
Output
● mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: en Active: active (running) since Thu 2022-02-24 18:59:22 UTC; 23min ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Main PID: 3722 (mysqld) Status: "Server is operational" Tasks: 38 (limit: 4915) Memory: 371.7M CGroup: /system.slice/mysql.service └─3722 /usr/sbin/mysqld Feb 24 18:59:21 sql-debian systemd[1]: Starting MySQL Community Server... Feb 24 18:59:22 sql-debian systemd[1]: Started MySQL Community Server.

The Active: active (running) line means MySQL is installed and running. In the next step, you’ll make the installation a little more secure.

Step 3 — Securing MySQL

MySQL comes with a command to perform a few security-related updates on your new install. You can run it now:

  1. mysql_secure_installation

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

First, you’re 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. Write y and press ENTER to enable it, or press 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 press ENTER to continue.

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

The rest of the prompts can be answered yes. You will be asked about removing anonymous MySQL users, disallowing remote root logins, removing the test database, and reloading privilege tables to ensure the previous changes take effect properly. These are all good ideas. Write y and press ENTER for each.

The script will exit after all the prompts are answered. Now your MySQL installation is reasonably secured. Next you’ll 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. You’ll use it to connect to the server and output some version and status information. 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 you want to run:

  1. mysqladmin -u root -p version

The output will result in what version of the MySQL server is running, its uptime, and some other status information as in the following:

Output
mysqladmin Ver 8.0.28 for Linux on x86_64 (MySQL Community Server - GPL) Copyright (c) 2000, 2022, Oracle and/or its affiliates. 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.28 Protocol version 10 Connection Localhost via UNIX socket UNIX socket /var/run/mysqld/mysqld.sock Uptime: 25 min 31 sec Threads: 2 Questions: 20 Slow queries: 0 Opens: 143 Flush tables: 3 Open tables: 62 Queries per second avg: 0.013

This output confirms that you’ve successfully installed and secured the latest MySQL server.

Conclusion

You’ve now installed the latest stable version of MySQL, which should work for many popular applications.

For more information about the basics of MySQL, we encourage you to check out the following tutorials:

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!

Hello, guys! I was following the steps and I got an error. Can someone help?

Setting up mysql-community-server (8.0.18-1debian10) ...
Failed to preset unit: File mysql.service: Link has been severed
/usr/bin/deb-systemd-helper: error: systemctl preset failed on mysql.service: No such file or directory
Failed to get unit file state for mysql.service: Link has been severed
mysql.service is a disabled or a static unit, not starting it.
Job for mysql.service failed because the control process exited with error code.
See "systemctl status mysql.service" and "journalctl -xe" for details.
invoke-rc.d: initscript mysql, action "start" failed.
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; bad; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2019-11-18 01:55:38 UTC; 10ms ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 2589 ExecStartPre=/usr/share/mysql-8.0/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
  Process: 2624 ExecStart=/usr/sbin/mysqld (code=exited, status=1/FAILURE)
 Main PID: 2624 (code=exited, status=1/FAILURE)
   Status: "Data Dictionary upgrade from MySQL 5.7 in progress"

Nov 18 01:55:37 debian10 systemd[1]: Starting MySQL Community Server...
Nov 18 01:55:38 debian10 systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILURE
Nov 18 01:55:38 debian10 systemd[1]: mysql.service: Failed with result 'exit-code'.
Nov 18 01:55:38 debian10 systemd[1]: Failed to start MySQL Community Server.
dpkg: error processing package mysql-community-server (--configure):
 installed mysql-community-server package post-installation script subprocess returned error exit status 1
dpkg: dependency problems prevent configuration of mysql-server:
 mysql-server depends on mysql-community-server (= 8.0.18-1debian10); however:
  Package mysql-community-server is not configured yet.

dpkg: error processing package mysql-server (--configure):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 mysql-community-server
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

Luís Fernando

Hello, First of all During step 1, I have an infinite loop on asking me: (1) MySQL Server & Cluster (Currently selected: mysql-8.0) (2) mysql-8.0 After escaping this infinite modal window, during step 2 — Installing MySQL, for debian 10 I have: E: Package ‘mysql-server’ has no installation candidate. Do you have any clue?

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!

Become a contributor for community

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

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.