The introduction

Recently, some cloud activities, bought a server as usual learning and testing, the new machine is nothing, some common software installation is inevitable, so I want to put the installation process are recorded in detail, one is to make a memo, the other is to have a reference for the students.

There are several common ways to install software on Linux:

  • The source code to compile
  • Decompress the compressed package (usually tar.gz)
  • Compiled installation packages (RPM, DPKG, etc.)
  • Install online (YUM, APT, etc.)

The above several ways of convenience, in turn, increases, but the general decline in turn, such as direct download package to extract, this approach usually works need to do some additional configuration, but as long as to master the method, the basic platform, YUM, although simple, but restricted platform, network limited, necessary should be added to some specific YUM source.

Several installation methods are best to master, in principle can use simple with simple: YUM>RPM>tar.gz> source code

MySQL installed on CentOS is introduced in this paper, the main steps are refer to the MySQL official document: dev.mysql.com/doc/refman/…

In order to test different installation methods, repeatedly toss over several times, install the delete, delete the installation, each step is the success of the test, each command is personally executed, can rest assured to use

Let’s cut short the gossip and get to the point.

A, YUM!

0. Delete the installed MySQL

Check the MariaDB
Shell > RPM - qa | grep mariadb mariadb server - 5.5.60-1. El7_5. X86_64 mariadb 5.5.60-1. El7_5. X86_64 Mariadb - libs - 5.5.60-1. El7_5. X86_64Copy the code
Delete the mariadb

If it does not exist (the check result above returns null) skip the step

shell> rpm -e --nodeps mariadb-server
shell> rpm -e --nodeps mariadb
shell> rpm -e --nodeps mariadb-libs
Copy the code

If you install MySQL, you can delete mariadb. If you install MySQL, you can override mariadb

Check the MySQL
shell> rpm -qa|grep mysql
Copy the code
Delete MySQL

If it does not exist (the check result above returns null) skip the step

shell> rpm -e --nodeps xxx
Copy the code

Add MySQL Yum Repository

Starting with CentOS 7, MariaDB is the default database installation package in the Yum source. MariaDB (a branch of MySQL) is installed by default with yum on CentOS 7 and above. If you want to install the official MySQL version, you need to use the Yum source provided by MySQL.

Download the MySQL source

Website address: dev.mysql.com/downloads/r…

Viewing the system version:

Shell > cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core)Copy the code

Choose corresponding version for download, for example in 7 current CentOS website to view the latest Yum source download address is: dev.mysql.com/get/mysql80…

shell> wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
Copy the code
Install the MySQL source
shell> sudo rpm -Uvh platform-and-version-specific-package-name.rpm
Copy the code

For example, CentOS7 is the latest MySQL source installed:

shell> sudo rpm -Uvh mysql80-community-release-el7-3.noarch.rpm
Copy the code
Check whether the installation is successful

Repo and mysql-community-source.repo are generated in the /etc/yom.repos. d/ directory

You can also see mysql related resources through yum Repolist

shell> yum repolist enabled | grep "mysql.*-community.*"! mysql-connectors-community/x86_64 MySQL Connectors Community 108 ! mysql-tools-community/x86_64 MySQL Tools Community 90 ! Mysql80-community /x86_64 MySQL 8.0 community Server 113Copy the code

2. Select the MySQL version

If you want to install MySQL from the MySQL source, you can skip this step. If you want to install MySQL from the MySQL source, you can skip this step. For example, if I want to install MySQL5.7, I need to “switch the version” :

View all MySQL versions in the current MySQL Yum Repository (each version in a different subrepository)
shell> yum repolist all | grep mysql
Copy the code
Switch version
shell> sudo yum-config-manager --disable mysql80-community
shell> sudo yum-config-manager --enable mysql57-community
Copy the code

In addition to using yum-config-manager, you can directly edit the /etc/yom.repos. d/ mysql-community-repo file

Enabled = 0 to disable

[mysql80 - community] name = MySQL community Server baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/ 8.0$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Copy the code

Enable enabled = 1

Enable to use MySQL 5.7[mysql57 - community] name = MySQL community Server baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/ 5.7$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Copy the code
Check the MySQL repository currently enabled
shell> yum repolist enabled | grep mysql
Copy the code

If multiple repositories are enabled at the same time, the latest version will be selected for installation

3, Install MySQL

shell> sudo yum install mysql-community-server
Copy the code

This command installs the MySQL server (mysql-community-server) and its dependencies and related components. Including mysql-community-client, mysql-community-common, and mysql-community-libs

If the bandwidth is insufficient, this step takes a long time. Please wait patiently for ~

4. Start MySQL

Start the
shell> sudo systemctl start mysqld.service
Copy the code

CentOS 6:

shell> sudo service mysqld start
Copy the code
Check the status
shell> sudo systemctl status mysqld.service
Copy the code

CentOS 6:

shell> sudo service mysqld status
Copy the code
stop
shell> sudo systemctl stop mysqld.service
Copy the code

CentOS 6:

shell> sudo service mysqld stop
Copy the code
restart
shell> sudo systemctl restart mysqld.service
Copy the code

CentOS 6:

shell> sudo service mysqld restart
Copy the code

5. Change the password

Initial password

The super administrator account root@localhost is created after the MySQL is started for the first time. The initial password is stored in the log file:

shell> sudo grep 'temporary password' /var/log/mysqld.log
Copy the code
Changing the Default Password
shell> mysql -uroot -p
Copy the code
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
Copy the code

The above prompt appears because the password is too simple, the solution is as follows:

  1. For complex passwords, MySQL’s default password policy is to contain numbers, letters, and special characters.
  2. If you do not want to use a complex password for testing purposes, you can change the default policyvalidate_password_policy(andvalidate_password_lengthAnd other related parameters), so that it supports the setting of simple password, specific methods can be baidu;
  3. Modifying a Configuration File/etc/my.cnfTo addvalidate_password=OFFSave and restart MySQL
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)
Copy the code

6. Allow remote access by root

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@The '%' IDENTIFIED BY '123456' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
Copy the code

7. Set the encoding to UTF8

Check the code
mysql> SHOW VARIABLES LIKE 'character%';
Copy the code
Set the coding

Add the following code to the /etc/my.cnf [mysqld] node:

[mysqld]
character_set_server=utf8
init-connect='SET NAMES utf8'
Copy the code

8. Set boot

shell> systemctl enable mysqld
shell> systemctl daemon-reload
Copy the code

Second, the RPM

Except for the installation process, other steps are the same as the YUM installation

0. Delete an earlier version

slightly

Download the MySQL installation package

Download address: dev.mysql.com/downloads/m…

Select the corresponding version:

Shell > wget HTTP: / / https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.26-1.el7.x86_64.rpm-bundle.tarCopy the code

2. Install MySQL

Decompress (unpack)
Shell > tar -xvf mysql-5.7.26-1.el7.x86_64. RPM -bundle.tar -xvf mysql-5.7.26-1.el7.x86_64. RPM -bundle.tar Mysql - community - embedded - devel - 5.7.26-1. El7. X86_64. RPM mysql - community - libs - 5.7.26-1. El7. X86_64. RPM Mysql - community - embedded - 5.7.26-1. El7. X86_64. RPM mysql - community - test - 5.7.26-1. El7. X86_64. RPM Mysql - community - embedded - compat - 5.7.26-1. El7. X86_64. RPM mysql - community - common - 5.7.26-1. El7. X86_64. RPM Mysql - community - devel - 5.7.26-1. El7. X86_64. RPM mysql - community - the client - 5.7.26-1. El7. X86_64. RPM Mysql - community - server - 5.7.26-1. El7. X86_64. RPMCopy the code

We mainly install these four (or others if necessary) :

Mysql - community - libs - 5.7.26-1. El7. X86_64. RPM mysql - community - common - 5.7.26-1. El7. X86_64. RPM Mysql - community - the client - 5.7.26-1. El7. X86_64. RPM mysql - community - server - 5.7.26-1. El7. X86_64. RPMCopy the code

If you don’t want to download rpM-bundle, the website also provides a separate RPM download link

The installation

RPM packages are dependent on each other, so you need to install them in a certain sequence. If any dependency is missing during installation, you need to install corresponding packages first:

Shell > RPM -ivh mysql-community-common-5.7.26-1. El7.x86_64. RPM shell> RPM -ivh RPM shell> RPM -ivh mysql-community-client-5.7.26-1. El7.x86_64. RPM shell> RPM - the ivh mysql - community - server - 5.7.26-1. El7. X86_64. RPMCopy the code

There is also a simple way to automatically handle dependencies between packages and automatically download missing dependencies:

shell> yum install mysql-community-{server,client,common,libs}-*
Copy the code

Note: aboveyum installThe command must be executed in the directory of each RPM package after tar decompression. Otherwise, it will be installed in yum mode. The yum source of MySQL needs to be configured and the speed is very slow

3, set up

slightly

Third, the tar. Gz

0. Delete the earlier version

slightly

1, download

Download address: dev.mysql.com/downloads/m…

Select the corresponding version:

Shell > wget HTTP: / / https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gzCopy the code

2. Installation & Configuration:

Rely on

MySQL depends on the libaio library.

shell> yum install libaio
Copy the code
Create mysql user

A system account that does not require login and is used to start the MySQL service

shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql
Copy the code
Unzip and create links
shell> cd /usr/localShell > tar ZXVF /path/to/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz shell> ln-sMysql - 5.7.26 - Linux - glibc2.12 x86_64 / mysqlCopy the code
Create mysql-files directory

This step is not necessary. You can set the value of secure_file_priv to point to this directory (used to restrict data import and export operations).

shell> cd mysql
shell> mkdir mysql-files
shell> chown mysql:mysql mysql-files
shell> chmod 750 mysql-files
Copy the code
Initialize the
shell> bin/mysqld --initialize --user=mysql
Copy the code

If the initialization error is as follows:

error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
Copy the code

Because libnuma is not installed (or 32-bit is installed by default), we need 64-bit here:

shell> yum install numactl.x86_64
Copy the code

If the initialization is successful, a line containing the initial password is returned. This line is required for the first login:

A temporary password is generated for root@localhost: 8M0ary878s*U
Copy the code
Enable SSL (optional)
shell> bin/mysql_ssl_rsa_setup
Copy the code
Start the
shell> bin/mysqld_safe --user=mysql &
Copy the code

Looking at the process, you can see some default parameters that can be modified in the configuration file

shell> ps -ef | grep mysql
root     14604 12719  0 00:03 pts/0    00:00:00 /bin/sh bin/mysqld_safe --user=mysql
mysql    14674 14604  0 00:03 pts/0    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=VM_2_24_centos.err --pid-file=VM_2_24_centos.pid
Copy the code
Setting environment Variables

To avoid adding a path every time you run a mysql command, add the following to /etc/profile:

export PATH=$PATH:/usr/local/mysql/bin
Copy the code
Set as service
shell> cp support-files/mysql.server /etc/init.d/mysqld
shell> service mysqld start|stop|restart|status
Copy the code
Powered up
Shell > chkconfig --add mysqld shell> chkconfig --list mysqld mysqld 0: off 1: off 2: on 3: on 4: on 5: on 6: offCopy the code

Other configurations are the same as those of yum and RPM

Four, source code installation

Don’t bother…

conclusion

We are not Linux operation and maintenance experts, nor MySQL experts, born in this era is also not happy or unfortunate, online environment has fewer and fewer people (mainly refers to usually write code people) to manually handle the installation and configuration of these databases, middleware, why? Because of various cloud products is too convenient ah, general company also can’t bad this a few money, convenient and stable, why not do it ~ but our own one for your test is necessary, and there are a lot of the company’s development environment, test environment or manually make occasionally, of course, there are those giants an own room.

Since we are not experts, the above content if there is a mistake is inevitable, if seen also hope to timely criticism and correction ~