Installing using the software packages requires some dependencies to be installed first and can conflict with other packages. In that case, you can install MySQL using the generic binaries available on the downloads page. Binaries are precompiled using advanced compilers and are built with the best possible options for optimal performance.
MySQL has a dependency on the libaio
library. The data directory
initialization, and subsequent server startup steps, will fail if this library is not installed locally.
On YUM-based systems:
shell> sudo yum install -y libaio
On APT-based systems:
shell> sudo apt-get install -y libaio1
Download the TAR binary from the MySQL Downloads
page, at https://dev.mysql.com/downloads/mysql/, then choose Linux - Generic
as the OS and select the version. You can download directly onto your server directly using the wget
command:
shell> cd /opt
shell> wget "https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.3-rc-linux-glibc2.12-x86_64.tar.gz"
Install MySQL using the following steps:
- Add the
mysql
group and themysql
user. All the files and directories should be under themysql
user:
shell> sudo groupadd mysql shell> sudo useradd -r -g mysql -s /bin/false mysql
- This is the installation location (you can change it to another location):
shell> cd /usr/local
- Untar the binary file. Keep the untarred binary file at the same location and symlink it to the installation location. In this way, you can keep multiple versions and it is very easy to upgrade. For example, you can download another version and untar it to a different location; while upgrading, all you need to do is to change the symlink:
shell> sudo tar zxvf /opt/mysql-8.0.3-rc-linux-glibc2.12-x86_64.tar.gz mysql-8.0.3-rc-linux-glibc2.12-x86_64/bin/myisam_ftdump mysql-8.0.3-rc-linux-glibc2.12-x86_64/bin/myisamchk
mysql-8.0.3-rc-linux-glibc2.12-x86_64/bin/myisamlog mysql-8.0.3-rc-linux-glibc2.12-x86_64/bin/myisampack mysql-8.0.3-rc-linux-glibc2.12-x86_64/bin/mysql ~
- Make the symlink:
shell> sudo ln -s mysql-8.0.3-rc-linux-glibc2.12-x86_64 mysql
- Create the necessary directories and change the ownership to
mysql
:
shell> cd mysql shell> sudo mkdir mysql-files shell> sudo chmod 750 mysql-files shell> sudo chown -R mysql . shell> sudo chgrp -R mysql .
- Initialize
mysql
, which generates a temporary password:
shell> sudo bin/mysqld --initialize --user=mysql
~
2017-12-02T05:55:10.822139Z 5 [Note] A temporary password is generated for root@localhost: Aw=ee.rf(6Ua
~
- Set up the RSA for SSL. Refer to Chapter 14, Setting up Encrypted Connections using X509 Section, for more details on SSL. Note that a temporary password is generated for
root@localhost: eJQdj8C*qVMq
:
shell> sudo bin/mysql_ssl_rsa_setup Generating a 2048 bit RSA private key ...........+++ ....................................+++ writing new private key to 'ca-key.pem' ----- Generating a 2048 bit RSA private key ...........................................................+++ ...........................................+++ writing new private key to 'server-key.pem' ----- Generating a 2048 bit RSA private key .....+++ ..........................+++ writing new private key to 'client-key.pem' -----
- Change the ownership of binaries to
root
anddata
files tomysql
:
shell> sudo chown -R root . shell> sudo chown -R mysql data mysql-files
- Copy the startup script to
init.d
:
shell> sudo cp support-files/mysql.server /etc/init.d/mysql
- Export the binary of
mysql
to thePATH
environment variable:
shell> export PATH=$PATH:/usr/local/mysql/bin
- Refer to Starting or Stopping MySQL 8 section to start MySQL.
After installation, you will get the following directories inside /usr/local/mysql
:
Directory | Contents of directory |
|
|
| Log files, databases |
| MySQL manual in info format |
| Unix manual pages |
| Include (header) files |
| Libraries |
| Miscellaneous support files, including error messages, sample configuration files, SQL for database installation |
There are other installation methods, such as:
- Compiling from the source code. You can compile and build MySQL from the source code provided by Oracle where you have the flexibility to customize build parameters, compiler optimizations, and the installation location. It is highly recommended to use precompiled binaries provided by Oracle, unless you want specific compiler options or you are debugging MySQL. This method is not covered as it is used very rarely and it requires several development tools, which is beyond the scope of this book. For installation through source code, you can refer to the reference manual, at https://dev.mysql.com/doc/refman/8.0/en/source-installation.html.
- Using Docker. The MySQL server can also be installed and managed using Docker image. Refer to https://hub.docker.com/r/mysql/mysql-server/ for installation, configuration, and also how to use MySQL under Docker.