Chat Zalo Chat Messenger Phone Number Đăng nhập
How To Install the Latest MySQL on Ubuntu 16.04 - DigitalOcean

How To Install the Latest MySQL on Ubuntu 16.04 – DigitalOcean

MySQL

is a leading 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 open source software suite that also includes Linux, the Apache web server, and the PHP programming language.

To use the newly released features, it is sometimes necessary to install a more up-to-date version of MySQL than that provided by your Linux distribution. Conveniently, MySQL developers maintain their own software repository that we can use to easily install the latest version and keep it up to date.

To install the

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

Prerequisites

Before you begin this tutorial, you

will need:

An Ubuntu 16.04 server

  • with a non-root sudo enabled user, as described in this Ubuntu 16.04 server setup tutorial

.

Step 1 — Add

the

MySQL software repository MySQL developers provide a .deb package that handles the configuration and installation of official MySQL software repositories. Once the repositories are configured, we can use Ubuntu’s standard apt-get command to install the software. We will download this file .deb with curl 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 the next page. This page will ask you to log in or register 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 let’s download the file. On your server, move

to a directory where you can write:

  1. cd /tmp

Download the file using curl

, remembering to paste the address you just copied instead of the highlighted part below:

curl –

  1. OL https://dev.mysql.com/get/mysql-apt-config_0.8.3-1_all.deb

We need to pass two command line flags for curl. -Or instructs curl to output a file instead of standard output. The L flag causes curl to follow HTTP redirects, necessary in this case because the address we copy actually redirects us to another location before the file is downloaded.

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

:

  1. ls

You should see the file name in the list:

Outputmysql-apt-config_0.8.3-1_all.deb . . .

Now we are ready

to install: sudo dpkg –

  1. i mysql-apt-config* dpkg

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

During installation, you will be presented with a configuration screen where you can specify which version of MySQL you 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 press ENTER.

The package will now finish adding the repository. Update the cache of your apt package

so that new software packages are available:

  1. sudo apt-get update

Let’s also clean up after ourselves and delete the file we downloaded:

  1. rm mysql-apt-config*

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, simply run sudo dpkg-reconfigure mysql-apt-config, select new options, and then sudo apt-get update to update your package cache.

Step 2 — Installing

MySQL

After we have added the repository and with our newly updated package cache, we can now use

apt-get to install the latest MySQL server package: sudo apt-get

  1. install mysql-server apt-get

will analyze all available mysql-server packages and determine that the package provided by MySQL is the newest and best candidate. It will then calculate the dependencies of the package and prompt you to approve the installation. Type y, and then ENTER. The software will be installed. You will be prompted to set a root password during the setup phase of the installation. Make sure you choose a strong password, enter it twice, and the process is complete.

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

systemctl:

  1. systemctl status

mysql Output● mysql.service – MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; provider preset: enabled) Active: active (running) since Wed 2017-04-05 19:28:37 UTC; 3min ago 42s Main PID: 8760 (mysqld) CGroup: /system.slice/mysql.service └─8760 /usr/sbin/mysqld -daemonize -pid-file=/var/run/mysqld/mysqld.pid

The line Active: active (running) means that MySQL is installed and running. Now we will make the installation a little safer.

Step 3 – Secure

MySQL

MySQL comes with a command that we can use to make some security-related updates on our new installation. Let’s run it now:

  1. mysql_secure_installation

This will prompt you for the MySQL root password you set during installation. Type it, and then press ENTER. Now we will answer a series of yes or no indications. Let’s go over them:

First, we’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. Type y and ENTER to enable it, or simply press ENTER to skip it. If enabled, you will also be asked to choose a level from 0-2 to know how strict the password validation will be. Choose a number and press ENTER to continue.

You will then be asked if you want to change the root password. Since we just created the password when we installed MySQL, we can safely bypass this. Press ENTER to continue without updating the password.

The rest of the indications can be answered affirmatively. You will be asked about removing the anonymous user from MySQL, not allowing remote root login, deleting the test database, and reloading the privilege tables to ensure that the above changes take effect correctly. All of these are a good idea. Type y and press ENTER for each.

The script will close after all 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 – MySQL Test

mysqladmin is a command-line administrative client for MySQL. We will use it to connect

to the server and generate version and status information: mysqladmin -u root -p version The root

part -u tells mysqladmin to log in as MySQL root user, -p tells the client to request a password and version is the actual command we want to execute. The

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

Outputmysqladmin Ver 8.42 Distrib 5.7.17, for Linux on x86_64 Copyright (c) 2000, 2016, 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 5.7.17 Protocol version 10 Localhost connection via UNIX socket UNIX socket /var/run/mysqld/mysqld.sock Uptime: 58 min 28 sec Threads: 1 Questions: 10 Slow queries: 0 Apertures: 113 Flush tables: 1 Open tables: 106 Queries per second Average: 0.002

If you received a similar result, congratulations! You have successfully installed the latest MySQL server and protected it.

Conclusion

You have now completed a basic installation of the latest version of MySQL, which should work for many popular applications. If you have more advanced needs, you can proceed with some other configuration tasks:

  • If you want a graphical interface to manage your MySQL server, phpMyAdmin is a popular web-based solution. Our tutorial How to install and secure phpMyAdmin can help you get started.
  • Currently, the database is only accessible to applications running on the same server. Sometimes you’ll want separate database and application servers, for performance and storage reasons. Take a look at How to Configure SSL/TLS for MySQL to learn how to configure MySQL for secure access from other servers.
  • Another common setting is to change the directory where MySQL stores your data. You will need to do this if you want your data to be stored on a storage device other than the default directory. This is covered in How to move a MySQL data directory to a new location.

Contact US