Four installation and deployment methods of database

Database installation

Experimental environment

Redhat8.3

Method 1: use the MySQL repository to install and deploy mysql

1, Add MySQL repository

Add the MySQL Yum repository to the repository list of the system. This is a one-time operation that can be performed by installing the RPM provided by mysql.

Follow these steps:

  1. Go to the download MySQL Yum repository page( https://dev.mysql.com/downloads/repo/yum/ )In MySQL development section

  2. Select and download the release package for your platform.

  3. Install the downloaded distribution package using the following command, and replace platform and version specific package name with the name of the downloaded RPM package:

    sudo yum install platform-and-version-specific-package-name.rpm
    
  4. On RHEL8 platform:

    Command template:

    sudo yum install mysql80-community-release-el8-{version_number}.noarch.rpm
    

    You can use the following commands:

    sudo rpm -i https://repo.mysql.com/mysql80-community-release-el8-2.noarch.rpm
    

2, Disable the default MySQL module

(EL8 systems only) EL8 based systems (such as RHEL8 and Oracle Linux 8) include MySQL modules enabled by default. Unless this module is disabled, it masks packages provided by the MySQL repository. To disable the included modules and make the MySQL repository package visible, use the following command (for dnf enabled systems, replace yum in the command with DNF):

sudo yum module disable mysql

3, Install MySQL

Install MySQL through the following command (for dnf enabled systems, replace yum in the command with DNF):

sudo yum install mysql-community-server

This will install the package of the MySQL server (MySQL community server) and the package of components required to run the server, including the package of the client (MySQL community client), common error messages and character sets of the client and server (shared by the MySQL community), and shared client library (MySQL Community Library).

4, Start MySQL server

1. Start the MySQL server with the following command

systemctl start mysqld

You can use the following command to check the status of the MySQL server

systemctl status mysqld

When the server is initially started, if the data directory of the server is empty, the following occurs:

  • The server has been initialized.

  • SSL certificate and key files are generated in the data directory.

  • validate_password is installed and enabled.

  • A super user 'root' @ 'localhost is created, and the password of the super user has been set and stored in the error log file.

2. View password:

sudo grep 'temporary password' /var/log/mysqld.log

Change the root password as soon as possible by logging in with the generated temporary password and setting a custom password for the super user account:

3. Enter the command from the Linux command line:

mysql -uroot -p

4. Enter the database and enter the command:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';

Authentication passwords are installed by default. validate_ The default password policy implemented by password requires that the password contain at least one uppercase letter, one lowercase letter, one number and one special character, and the total password length is at least 8 characters.

5, Service confirmation

1. Service check

systemctl status mysqld
systemctl is-active mysqld
systemctl is-enable mysqld

2. Port check

netstat -lntup | grep 3306
lsof -i tcp:3306

3. Process check

ps -ef | grep mysql

Method 2: install MySQL offline

1, Use the following to clean up the database installed in the previous experimental MySQL warehouse:

dnf remove mysql-community-server
rm -rf /var/lib/mysql/
rm -rf /usr/lib64/mysql/
rm -rf /var/log/mysqld.log

2, Download the mysql installation package from the Internet

Open link https://dev.mysql.com/downloads/mysql/ , select the corresponding version to download.

I downloaded mysql-8.0.27-1.el8.x86_64.rpm-bundle.tar

3, Transfer the downloaded file to a path in Redhat

dnf install lrzsz -y
rz

4, Unzip the installation package

tar –xvf mysql-8.0.27-1.el8.x86_64.rpm-bundle.tar

5, Install using the following instructions

dnf localinstall mysql-community-server-8.0.27-1.el8.x86_64.rpm \
mysql-community-client-8.0.27-1.el8.x86_64.rpm \
mysql-community-client-plugins-8.0.27-1.el8.x86_64.rpm \
mysql-community-libs-8.0.27-1.el8.x86_64.rpm \
mysql-community-common-8.0.27-1.el8.x86_64.rpm

Alternatively, you can use the following instructions:

dnf install *.rpm

Method 3: deploy MySQL using Docker

Docker deployment framework supports easy installation and configuration of MySQL server.

You need to install Docker on the system before using the MySQL server Docker image.

1, Prepare Docker environment

1. Dependent package installation

dnf install -y yum-utils device-mapper-persistent-data lvm2

2. Download official warehouse

wget -O /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo

3. Install Docker

dnf install docker-ce -y

4. Start service

systemctl start docker

2, Download the MySQL server Docker image

Strictly speaking, there is no need to download the server image in a separate step; However, performing this step before creating the Docker container ensures that the local image is up-to-date. To download the MySQL Community Edition image, run the following command:

1. Download MySQL Community Edition image

docker pull mysql/mysql-server:tag

tag is the label of the mirror version to extract (for example, 5.6, 5.7, 8.0, or the latest version).

If: tag is omitted, use the latest tag and download the image of the latest GA version of MySQL Community Server.

To download the MySQL Community Edition image from the Oracle container Registry (OCR), run the following command (login is required, and this command is generally not used):

docker pull container-registry.oracle.com/mysql/mysql-server:tag

2. The following instructions can also be used directly

Search image

docker search mysql

Pull image

docker pull mysql

List mirrors

docker image ls

3, Start MySQL server instance

docker run --name mysqltest -e MYSQL_ROOT_PASSWORD=123456 -d mysql/mysql-server

If the previous Docker pull or Docker run command did not download the Docker image with the specified name and tag, the image will now be downloaded. The initialization of the container starts. When you run the docker ps command, the container will be displayed in the list of running containers. For example:

docker ps

View port

netstat -lntup | grep 3306

Attach to container

docker exec -it mysqltest /bin/bash

Using client tests

mysql -uroot -p

Clean up the environment

docker stop mysqltest 
docker container prune

If you need to specify parameters to run the container, you can refer to the following command:

Specify the configuration file (just understand and do not execute)

docker run --name some-mysql -v /my/custom:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag

Specify storage (just understand and do not execute)

docker run --name some-mysql -v /my/own/datadir:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag

Mode 4: source code installation

1, Download and unzip the source package

Use the following instructions to download the source package from the official website

wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-boost-8.0.27.tar.gz

You can also open links https://dev.mysql.com/downloads/mysql/ , select source code on the page, select the source code package with boost, download it and upload it to the system.

Unzip the file using the following command

tar xf mysql-boost-8.0.27.tar.gz -C /usr/local/src/

Preparing the compilation environment

Install the compilation environment tool using the following command:

dnf install openssl-devel cmake make gcc gcc-c++ ncurses gcc-toolset-10 libtirpc-devel rpcgen ncurses-devel make

2, Create user groups and directories

add group

groupadd mysql

Add user

useradd -r -g mysql -s /bin/false mysql

Enter directory

cd /usr/local/src/mysql-8.0.27/ 
mkdir bld 
cd bld/

3, Compile configuration

cmake ..

Clean up the environment if compiling the configuration fails

make clean 
rm CMakeCache.txt

compile

make

install

make install

What to do after compilation

cd /usr/local/mysql/
mkdir mysql-files
chown mysql:mysql mysql-files/
chmod 750 mysql-files/
bin/mysqld --initialize --user=mysql

After the execution, be sure to remember the temporary password output above

[Server] A temporary password is generated for root@localhost: 8selIRYu7%tV
bin/mysql_ssl_rsa_setup
bin/mysqld_safe --user=mysql &
cp support-files/mysql.server /etc/init.d/mysql.server

Startup required:

vim /etc/rc.d/rc.local
service mysql start

Environment variable required

vim /root/.bash_profile
PATH=$PATH:/usr/local/mysql/bin

Keywords: Linux Database MySQL bash server

Added by Dragoa on Sun, 28 Nov 2021 15:11:38 +0200