The most common and easiest way of installation is through software repositories where you add official Oracle MySQL repositories to your list and install MySQL through package management software.
There are mainly two types of repository software:
- YUM (Centos, Red Hat, Fedora and Oracle Linux)
- APT (Debian, Ubuntu)
How to do it...
Let's look at steps for installing MySQL 8 in the following ways:
Using YUM repositories
- Find the Red Hat or CentOS version:
shell> cat /etc/redhat-release CentOS Linux release 7.3.1611 (Core)
- Add the MySQL Yum repository to your system's repository list. This is a one-time operation that can be performed by installing an RPM provided by MySQL.
You can download the MySQL YUM Repository from this link and choose the file depending on your OS.
Install the downloaded release package with the following command, replacing the name with the platform- and version-specific package name of the downloaded RPM package:
shell> sudo yum localinstall -y mysql57-community-release-el7-11.noarch.rpm Loaded plugins: fastestmirror Examining mysql57-community-release-el7-11.noarch.rpm: mysql57-community-release-el7-11.noarch Marking mysql57-community-release-el7-11.noarch.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package mysql57-community-release.noarch 0:el7-11 will be installed --> Finished Dependency Resolution ~ Verifying : mysql57-community-release-el7-11.noarch 1/1 Installed: mysql57-community-release.noarch 0:el7-11 Complete!
- Or you can copy the link location and install directly using RPM (you can skip the next step after installing):
shell> sudo rpm -Uvh "https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm" Retrieving https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm Preparing... ################################# [100%] Updating / installing... 1:mysql57-community-release-el7-11 ################################# [100%]
- Verify the installation:
shell> yum repolist enabled | grep 'mysql.*-community.*' mysql-connectors-community/x86_64 MySQL Connectors Community 42 mysql-tools-community/x86_64 MySQL Tools Community 53 mysql57-community/x86_64 MySQL 5.7 Community Server 227
- Set the release series. At the time of writing this book, MySQL 8 is not a general availability (GA) release. So MySQL 5.7 will be selected as the default release series. To install MySQL 8, you have to set the release series to 8:
shell> sudo yum repolist all | grep mysql mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community disabled mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community disabled mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community disabled mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community disabled mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 42 mysql-connectors-community-source MySQL Connectors Community disabled mysql-tools-community/x86_64 MySQL Tools Community enabled: 53 mysql-tools-community-source MySQL Tools Community - Sou disabled mysql-tools-preview/x86_64 MySQL Tools Preview disabled mysql-tools-preview-source MySQL Tools Preview - Sourc disabled mysql55-community/x86_64 MySQL 5.5 Community Server disabled mysql55-community-source MySQL 5.5 Community Server disabled mysql56-community/x86_64 MySQL 5.6 Community Server disabled mysql56-community-source MySQL 5.6 Community Server disabled mysql57-community/x86_64 MySQL 5.7 Community Server enabled: 227 mysql57-community-source MySQL 5.7 Community Server disabled mysql80-community/x86_64 MySQL 8.0 Community Server disabled mysql80-community-source MySQL 8.0 Community Server disabled
shell> sudo yum install yum-utils.noarch -y shell> sudo yum-config-manager --disable mysql57-community shell> sudo yum-config-manager --enable mysql80-community
- Verify that
shell> sudo yum repolist all | grep mysql8 mysql80-community/x86_64 MySQL 8.0 Community Server enabled: 16 mysql80-community-source MySQL 8.0 Community Server disabled
- Install MySQL 8:
shell> sudo yum install -y mysql-community-server Loaded plugins: fastestmirror mysql-connectors-community | 2.5 kB 00:00:00 mysql-tools-community | 2.5 kB 00:00:00 mysql80-community | 2.5 kB 00:00:00 Loading mirror speeds from cached hostfile * base: mirror.web-ster.com * epel: mirrors.cat.pdx.edu * extras: mirrors.oit.uci.edu * updates: repos.lax.quadranet.com Resolving Dependencies ~ Transaction test succeeded Running transaction Installing : mysql-community-common-8.0.3-0.1.rc.el7.x86_64 1/4 Installing : mysql-community-libs-8.0.3-0.1.rc.el7.x86_64 2/4 Installing : mysql-community-client-8.0.3-0.1.rc.el7.x86_64 3/4 Installing : mysql-community-server-8.0.3-0.1.rc.el7.x86_64 4/4 Verifying : mysql-community-libs-8.0.3-0.1.rc.el7.x86_64 1/4 Verifying : mysql-community-common-8.0.3-0.1.rc.el7.x86_64 2/4 Verifying : mysql-community-client-8.0.3-0.1.rc.el7.x86_64 3/4 Verifying : mysql-community-server-8.0.3-0.1.rc.el7.x86_64 4/4 Installed: mysql-community-server.x86_64 0:8.0.3-0.1.rc.el7 Dependency Installed: mysql-community-client.x86_64 0:8.0.3-0.1.rc.el7 mysql-community-common.x86_64 0:8.0.3-0.1.rc.el7 mysql-community-libs.x86_64 0:8.0.3-0.1.rc.el7 Complete!
- You can check the installed packages using the following:
shell> rpm -qa | grep -i 'mysql.*8.*' perl-DBD-MySQL-4.023-5.el7.x86_64 mysql-community-libs-8.0.3-0.1.rc.el7.x86_64 mysql-community-common-8.0.3-0.1.rc.el7.x86_64 mysql-community-client-8.0.3-0.1.rc.el7.x86_64 mysql-community-server-8.0.3-0.1.rc.el7.x86_64
Using APT repositories
- Add the MySQL APT repository to your system's repository list. This is a one-time operation that can be performed by installing a .deb file provided by MySQL
You can download the MySQL APT repository from this url.
Or you can copy the link location and use wget to download directly on to the server. You might need to install wget (sudo apt-get install wget):
shell> wget "https://repo.mysql.com//mysql-apt-config_0.8.9-1_all.deb"
- Install the downloaded release package with the following command, replacing the name with platform- and version-specific package name of the downloaded APT package:
shell> sudo dpkg -i mysql-apt-config_0.8.9-1_all.deb (Reading database ... 131133 files and directories currently installed.) Preparing to unpack mysql-apt-config_0.8.9-1_all.deb ... Unpacking mysql-apt-config (0.8.9-1) over (0.8.9-1) ... Setting up mysql-apt-config (0.8.9-1) ... Warning: apt-key should not be used in scripts (called from postinst maintainerscript of the package mysql-apt-config) OK
- During the installation of the package, you will be asked to choose the versions of the MySQL server and other components. Press Enter for selecting and the Up and Down keys for navigating.
Select MySQL Server and Cluster (Currently selected: mysql-5.7).
Select mysql-8.0 preview (At the time of writing, MySQL 8.0 is not GA). You might get a warning such as MySQL 8.0-RC Note that MySQL 8.0 is currently an RC. It should only be installed to preview upcoming features of MySQL, and is not recommended for use in production environments. (RC is short for release candidate).
If you want to change the release version, execute the following:
shell> sudo dpkg-reconfigure mysql-apt-config
- Update package information from the MySQL APT repository with the following command (this step is mandatory):
shell> sudo apt-get update
- Install MySQL. During installation, you'll need to provide a password for the root user for your MySQL installation. Remember the password; if you forget it, you'll have to reset the root password (refer to the Resetting root password section). This installs the package for the MySQL server, as well as the packages for the client and for the database common files:
shell> sudo apt-get install -y mysql-community-server ~ Processing triggers for ureadahead (0.100.0-19) ... Setting up mysql-common (8.0.3-rc-1ubuntu14.04) ... update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) in auto mode Setting up mysql-community-client-core (8.0.3-rc-1ubuntu14.04) ... Setting up mysql-community-server-core (8.0.3-rc-1ubuntu14.04) ... ~
- Verify packages. ii indicates that the package is installed:
shell> dpkg -l | grep -i mysql ii mysql-apt-config 0.8.9-1 all Auto configuration for MySQL APT Repo. ii mysql-client 8.0.3-rc-1ubuntu14.04 amd64 MySQL Client meta package depending on latest version ii mysql-common 8.0.3-rc-1ubuntu14.04 amd64 MySQL Common ii mysql-community-client 8.0.3-rc-1ubuntu14.04 amd64 MySQL Client ii mysql-community-client-core 8.0.3-rc-1ubuntu14.04 amd64 MySQL Client Core Binaries ii mysql-community-server 8.0.3-rc-1ubuntu14.04 amd64 MySQL Server ii mysql-community-server-core 8.0.3-rc-1ubuntu14.04 amd64 MySQL Server