Introduction MySQL is a prominent open-source relational database management system (RDBMS) used to create, 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. When MySQL […]
MySQL is a prominent open-source relational database management system (RDBMS) used to create, 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.
When MySQL releases new features, you may need to install a more up-to-date version than what your Linux distributor provides. For this reason, MySQL developers share their own software repository to install the latest version.
In this tutorial, you will install the latest version of MySQL. Before doing so, you will need to add the MySQL software repository. Then, you will install the MySQL software itself, secure the install, and verify that MySQL is running and responding to commands.
Before starting this tutorial, you will need:
The MySQL developers provide a
.deb package that configures and installs the official MySQL software repositories. Once the repositories are set up, you will run Ubuntu’s standard
apt command to install the software. To do this, you will download the
.deb file with
curl and then install it with the
First, load the MySQL download page in your web browser. Find the Download button in the right corner and press it to get to the next page. This page will prompt you to log in or sign up for an Oracle web account. Ignore this and locate 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).
Next, you will download the file. On your server, move to a directory you can write to:
- cd /tmp
Download the file using
curl and replace the highlighted URL with the address you copied from the MySQL Download page:
- curl -OL https://dev.mysql.com/get/mysql-apt-config_0.8.18-1_all.deb
This command uses two flags with
curl to output to a file instead of standard output. The
L flag makes
curl follow HTTP redirects, because the address you copied actually redirects to another location before the file downloads.
The file is now downloaded in your current directory. List the files to make sure:
You will see the filename listed:
Outputmysql-apt-config_0.8.18-1_all.deb . . .
Now you can use
dpkg to begin the install:
- sudo dpkg -i mysql-apt-config*
dpkg is used to install, remove, and inspect
.deb software packages. The
-i flag requests to install from the specified file.
During installation, you’ll be prompted with a configuration screen where you can choose which version of MySQL you prefer, and an option to install repositories for other MySQL-related tools.
Since you only want to install the latest version of MySQL, you can choose
Ok from the menu options and press
ENTER. The repository information you need is already included with the defaults.
The package will finish adding the repository. Then you can refresh your
apt package cache to make the new software packages available:
- sudo apt update
Tidy everything up by deleting the file download with the
- rm mysql-apt-config*
Now that the MySQL repositories are added, you’re ready to install the actual MySQL server software. You can update the configuration of these repositories in the future by running
sudo dpkg-reconfigure mysql-apt-config, selecting new options, and then
sudo apt update to refresh your package cache.
With your new repository added and package cache freshly updated, you will use
apt to install the latest MySQL server package:
- sudo apt install mysql-server
apt identifies all available
mysql-server packages and confirms that the MySQL package is the newest version. Then, it will calculate package dependencies and prompt you to approve the installation. Type
ENTER to proceed with the installation.
You will be asked to create a root password during the configuration phase of the installation. Be sure to choose a secure password. After you enter the password twice and hit
ENTER, you will be asked to configure an authentication plugin. The default of Use Strong Password Encryption is recommended, so press
ENTER to choose it. The installation process will continue until finished.
MySQL is now installed and running. You can check with
- systemctl status mysql
Output● mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: > Active: active (running) since Thu 2021-08-05 22:11:42 UTC; 1min 23s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 5268 ExecStartPre=/usr/share/mysql-8.0/mysql-systemd-start pre (cod> Main PID: 5322 (mysqld) Status: "Server is operational" Tasks: 37 (limit: 9513) Memory: 353.3M CGroup: /system.slice/mysql.service └─5322 /usr/sbin/mysqld
MySQL is installed and running if you see
Active: active (running). Next, you will secure your installation.
MySQL comes with a command we can use to perform a few security-related updates on our new install. Run the following command:
This command will bring up the configuration screen from earlier and ask for the MySQL root password credentials you created upon installation. Type it in and press
ENTER. Then, you will answer a series of yes or no prompts. This is what they’ll ask:
First, you will be asked whether you want to enable 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
ENTER to enable it, or press
ENTER to skip it. If enabled, you will also be prompted to choose a level from 0–2 on how strict the password validation will be. Choose a number and hit
ENTER to continue.
Second, you’ll be asked if you want to change the root password. Since you created the password during installation, you can safely skip this. Hit
ENTER to continue without updating the password.
Lastly, the other 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. Type
y and hit
ENTER for each.
The configuration screen will disappear after all the prompts are answered. This indicates your MySQL installation is reasonably secured. You can confirm by running a client that connects to the server and returns some information.
mysqladmin is a command line administrative client for MySQL. You will use it connect to the server and output some version and status information:
- mysqladmin -u root -p version
-u root portion of this command 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:
Outputmysqladmin Ver 8.0.26 for Linux on x86_64 (MySQL Community Server - GPL) Copyright (c) 2000, 2021, 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.26 Protocol version 10 Connection Localhost via UNIX socket UNIX socket /var/run/mysqld/mysqld.sock Uptime: 31 min 1 sec Threads: 2 Questions: 12 Slow queries: 0 Opens: 130 Flush tables: 3 Open tables: 49 Queries per second avg: 0.006
This output indicates that you’ve successfully installed and secured the latest MySQL server.
You’ve now completed a basic install of the latest version of MySQL, which will work for many popular applications. If you have more advanced needs you can apply some other configuration tasks: