MySQL is a well-known open source database management system used to store and retrieve data from various popular applications. MySQL is M in the LAMP stack. It is a set of commonly used open source software, including Linux, Apache web server and PHP programming language.
In order to use newly released features, sometimes it is necessary to install a newer version of MySQL than the one provided by the Linux distribution. Conveniently, MySQL developers maintain their own software repository, which 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, protect the installation, and finally we will test whether MySQL is running and respond to commands.
Before starting this tutorial, you need to:
sudo
command has been set up, and the firewall has been turned on. Students who don’t have a server can buy it from here, but I personally recommend you to use the free Tencent Cloud Developer Lab for experimentation, and then purchase server.MySQL developers provide a .deb
package for handling configuration and installation of the official MySQL software repository. Once the repository is set up, we can use Ubuntu's standard apt
command to install the software. We will use curl
to download this .deb
file, and then use the dpkg
command to install it.
First, load MySQL download page in a web browser. Find the "Download" button in the lower right corner, and click the next page. This page will prompt you to log in or register for an Oracle web account. We can skip this and instead look for links that say no need, just start my download**. Right-click the link and select "Copy Link Address" (The wording of this option may be different, depending on your browser).
Now we are going to download the file. On your server, move to a directory where you can write:
cd /tmp
Use curl
to download the file, remember to paste the address you just copied instead of the highlighted part below:
curl -OL https://dev.mysql.com/get/mysql-apt-config_0.8.10-1_all.deb
We need to pass two command line flags curl
. -O
instructs curl
to output to a file instead of standard output. The L
flag makes curl
follow HTTP redirects, which is necessary in this case because the address we copied 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 ensure:
ls
You should see the file name listed:
mysql-apt-config_0.8.10-1_all.deb
...
Now we are ready to install:
sudo dpkg -i mysql-apt-config*
dpkg
is used to install, delete and check the .deb
package. The -i
flag indicates that we want to install from the specified file.
During the installation process, you will see a configuration screen where you can specify your preferred MySQL version, as well as options for installing repositories for other MySQL-related tools. The default value will add the repository information of the latest stable version of MySQL, but 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. Flush the apt
package cache to make new packages available:
sudo apt update
Let's clean up and delete the files we downloaded by ourselves:
rm mysql-apt-config*
Now that we have added the MySQL repository, we are ready to install the actual MySQL server software. If you need to update the configuration of these repositories, just run sudo dpkg-reconfigure mysql-apt-config
, select the new option, and then sudo apt update
to refresh the package cache.
With the repository added and recently updated using our package cache, we can now install the latest MySQL server package using apt
:
sudo apt install mysql-server
apt
will look at all available mysql-server
packages and determine that the packages provided by MySQL are the latest and best candidates. It will then calculate the package dependencies and ask you to approve the installation. Type y
and then ENTER
. The software will install.
The system will ask you to set the root password during the configuration phase of the installation. Be sure to choose a secure password. After entering it twice and hitting ENTER
, you will be prompted to configure the authentication plugin. It is recommended to **use **the default "Encrypt with strong password", so please click ENTER
to select it. The installation process will continue to completion.
MySQL should now be installed and running. Let's check the use of systemctl
:
systemctl status mysql
● mysql.service - MySQL Community Server
Loaded:loaded(/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active:active(running) since Thu 2018-07-1217:46:42 UTC; 17s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Main PID:7918(mysqld)
Status:"SERVER_OPERATING"
Tasks:37(limit:1152)
CGroup:/system.slice/mysql.service
└─7918/usr/sbin/mysqld
The Active: active (running)
line means that MySQL is installed and running. Now we will make the installation more secure.
MySQL comes with a command that we can use to perform some security-related updates on the new installation. Let's run it now:
mysql_secure_installation
This will ask you for the MySQL root password you set during installation. Type and press ENTER
. Now we will answer a series of yes or no prompts. Let's see:
First, we were asked about Verify Password Plugin, which is a plugin that can automatically enforce certain password strength rules for MySQL users. Enabling this feature is a decision you need to make based on your personal security needs. Enter y
and ENTER
to enable it, or just hit ENTER
to skip it. If enabled, the system will also prompt you to select a level from 0-2 to determine the strictness of password verification. Select a number and click ENTER
to continue.
Next, you will be asked if you want to change the root password. Since we just created the password when installing MySQL, we can safely skip this. Click ENTER
to continue without updating the password.
The remaining prompts can be answered yes. The system will ask you whether to delete the anonymous MySQL user, prohibit remote root login, delete the test database, and reload the permission table to ensure that the previous changes take effect. These are all good ideas. Type y
and click ENTER
for each item.
After answering all prompts, the script will exit. Now our MySQL installation is reasonably safe. Let's test it again by running the client connected to the server and return some information.
mysqladmin
is a command line management client for MySQL. We will use it to connect to the server and output some version and status information:
mysqladmin -u root -p version
The -u root
part tells mysqladmin
to log in as the MySQL root user, -p
instructs the client to ask for a password, this version
is the actual command we want to run.
The output will tell us which version of the MySQL server is running, uptime, and some other status information:
mysqladmin Ver 8.0.11for 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.11
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/run/mysqld/mysqld.sock
Uptime:2 min 21 sec
Threads:2 Questions:10 Slow queries:0 Opens:136 Flush tables:2 Open tables:112 Queries per second avg:0.070
If you receive similar output, congratulations! You have successfully installed and protected the latest MySQL server.
You have now completed the basic installation of the latest version of MySQL, which should work for many popular applications.
For more Ubuntu tutorials, please go to [Tencent Cloud + Community] (https://cloud.tencent.com/developer?from=10680) to learn more.
Reference: "How To Install the Latest MySQL on Ubuntu 18.04"
Recommended Posts