CentOS 7 installs MySQL and MariaDB in more than one way

CentOS 7 Binary Installation MySQL 5.7

Environmental Science

Host: CentOS Linux release 7.9.2009 (Core) Minimal Install

Install using the Linux - Generic TAR package

Mysql Compressed Pack Official Download Address: https://downloads.mysql.com/archives/community/

Select Version:5.7.31
Select Operating System:Linux - Generic
Select OS Version:Linux - Generic (glibc 2.12) (x86, 64-bit)
Download from the list:
Compressed TAR Archive: mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz

Get ready

Close firewall and selinux

systemctl stop firewalld
systemctl disable firewalld

setenforce 0
sed -i 's/=enforcing/=disabled/g' /etc/sysconfig/selinux

Uninstall the mariadb client that comes with the system

# View the Mariadb that comes with the system
[root@node1 ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
# Uninstall Mariadb from the system
[root@node1 ~]# rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64

Create Installation Path

# mysql program directory
[root@node1 ~]# mkdir -p /mysql/app
# mysql data directory
[root@node1 ~]# mkdir -p /mysql/data/3306
# mysql log directory
[root@node1 ~]# mkdir -p /mysql/log/3306

Create Users and Groups

# Create User Groups
[root@node1 ~]# groupadd -g 1001 mysql
# Create User
[root@node1 ~]# useradd -r -g mysql -s /bin/false -u 1001 mysql

install

Upload and unzip mysql package

# Unzip installation package
[root@node1 ~]# tar -zxvf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz -C /mysql/app/
# Rename installation package
[root@node1 ~]# mv /mysql/app/mysql-5.7.31-linux-glibc2.12-x86_64/ /mysql/app/mysql

Create profile my.cnf

[root@node1 ~]# vi /mysql/data/3306/my.cnf
[mysql]
# set mysql client default chararter
default-character-set=utf8


[mysqld]
# set mysql server port  
port=3306
socket=/mysql/data/3306/mysql.sock
# set mysql install base dir
basedir=/mysql/app/mysql
# set the data store dir
datadir=/mysql/data/3306
# set the number of allow max connnection
max_connections=200
# set server charactre default encoding
character-set-server=utf8mb4
# the storage engine
default-storage-engine=INNODB
innodb_buffer_pool_size=200M
lower_case_table_names=1
max_allowed_packet=16M
explicit_defaults_for_timestamp=true
log-output=FILE
general_log=0
general_log_file=/myysql/log/3306/db-general.err
slow_query_log=ON
slow_query_log_file=/mysql/log/3306/db-query.err
long_query_time=10
log-error=/mysql/log/3306/db-error.err

# Create profile soft links
[root@node1 ~]# ln -sf /mysql/data/3306/my.cnf /etc/my.cnf
# Create sock soft link
[root@node1 ~]# ln -sf /mysql/data/3306/mysql.sock /tmp/mysql.sock

Initialization

# Directory Authorization
[root@node1 ~]# chown -R mysql:mysql /mysql

# Initialization
[root@node1 ~]# /mysql/app/mysql/bin/mysqld --initialize --user=mysql --basedir=/mysql/app/mysql/ --datadir=/mysql/data/3306/


# View Initialization root Password
[root@node1 ~]# cat /mysql/log/3306/db-error.err 
2020-12-05T18:46:13.226586Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-12-05T18:46:13.271620Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-12-05T18:46:13.344337Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 262b1196-372a-11eb-8924-000c29251f98.
2020-12-05T18:46:13.345989Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-12-05T18:46:14.341174Z 0 [Warning] CA certificate ca.pem is self signed.
2020-12-05T18:46:14.473638Z 1 [Note] A temporary password is generated for root@localhost: y.zI8QQTRjs7

At this point, the mysql installation is complete

Post-setup

Join systemd management

[root@node1 ~]# vi /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Community Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target


[Install]
WantedBy=multi-user.target
Alias=mysql.service


[Service]
User=mysql
Group=mysql
# Specify Type=forking to configure PID or specify daemonize to run
Type=forking

PermissionsStartOnly=true
ExecStart=/mysql/app/mysql/bin/mysqld --defaults-file=/mysql/data/3306/my.cnf --daemonize
LimitNOFILE = 65536
LimitNPROC = 65536 

# Reload the systemd file
[root@node1 ~]# systemctl daemon-reload

Configuring environment variables (global)

# Add export PATH=$PATH:/mysql/app/mysql/bin/at the end of/etc/profile
[root@node1 ~]# vi /etc/profile.d/mysql.sh
# set mysql environment
export PATH=$PATH:/mysql/app/mysql/bin/

# Reload/etc/profile
[root@node1 ~]# source /etc/profile

Modify password and authorize

# Open mysql
[root@node1 ~]# systemctl start mysqld

# Log in to mysql
[root@node1 ~]# mysql -uroot -p
Enter password:  # Enter the initialization password here
# Set the root user's new password to qwert123..
mysql> SET PASSWORD=PASSWORD("qwert123..");
Query OK, 0 rows affected, 1 warning (0.00 sec)

# Grant root login rights to all databases (tables) and all hosts to the user
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'qwert123..' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)

# Refresh Permissions
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.16 sec)

CentOS 7 Binary Installation MariaDB 10.4

Environmental Science

Host: CentOS Linux release 7.9.2009 (Core) Minimal Install

Install using the Linux - Generic TAR package

MariaDB Compressed Pack Official Download Address: https://mariadb.org/download/

MariaDB Server Version: MariaDB Server 10.4.21
Operating System: Linux
Architecture: x86_64
Init System: Systemd

Get ready

Close firewall and selinux

systemctl stop firewalld
systemctl disable firewalld

setenforce 0
sed -i 's/=enforcing/=disabled/g' /etc/sysconfig/selinux

Create Installation Path

# mysql program directory
[root@node1 ~]# mkdir -p /mysql/app
# mysql data directory
[root@node1 ~]# mkdir -p /mysql/data/3306
# mysql log directory
[root@node1 ~]# mkdir -p /mysql/log/3306

Create Users and Groups

# Create User Groups
[root@node1 ~]# groupadd -g 1001 mysql
# Create User
[root@node1 ~]# useradd -r -g mysql -s /bin/false -u 1001 mysql

install

Upload and unzip MariaDB compressed package

# Unzip installation package
[root@node1 ~]# tar -zxvf mariadb-10.4.21-linux-systemd-x86_64.tar.gz -C /mysql/app/
# Rename installation package
[root@node1 ~]# mv /mysql/app/mariadb-10.4.21-linux-systemd-x86_64 /mysql/app/mysql

Create profile my.cnf

[root@node1 ~]# vi /mysql/data/3306/my.cnf
[mysql]
# set mysql client default chararter
default-character-set=utf8


[mysqld]
# set mysql server port  
port=3306
socket=/mysql/data/3306/mysql.sock
# set mysql install base dir
basedir=/mysql/app/mysql
# set the data store dir
datadir=/mysql/data/3306
# set the number of allow max connnection
max_connections=200
# set server charactre default encoding
character-set-server=utf8mb4
# the storage engine
default-storage-engine=INNODB
innodb_buffer_pool_size=200M
lower_case_table_names=1
max_allowed_packet=16M
explicit_defaults_for_timestamp=true
log-output=FILE
general_log=0
general_log_file=/myysql/log/3306/db-general.err
slow_query_log=ON
slow_query_log_file=/mysql/log/3306/db-query.err
long_query_time=10
log-error=/mysql/log/3306/db-error.err

# Create profile soft links
[root@node1 ~]# ln -sf /mysql/data/3306/my.cnf /etc/my.cnf
# Create sock soft link

[root@node1 ~]# mkdir /var/lib/mysql/ -p
[root@node1 ~]# ln -sf /mysql/data/3306/mysql.sock /var/lib/mysql/mysql.sock

Initialization

# Directory Authorization
[root@node1 ~]# chown -R mysql:mysql /mysql

# Initialization
[root@localhost ~]# /mysql/app/mysql/scripts/mysql_install_db --user=mysql --basedir=/mysql/app/mysql/ --defaults-file=/etc/my.cnf
Installing MariaDB/MySQL system tables in '/mysql/data/3306' ...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system


Two all-privilege accounts were created.
One is root@localhost, it has no password, but you need to
be system 'root' user to connect. Use, for example, sudo mysql
The second is mysql@localhost, it has no password either, but
you need to be the system 'mysql' user to connect.
After connecting you can set the password, if you would need to be
able to connect as any of these users with a password and without sudo

See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.

You can start the MariaDB daemon with:
cd '/mysql/app/mysql/' ; /mysql/app/mysql//bin/mysqld_safe --datadir='/mysql/data/3306'

You can test the MariaDB daemon with mysql-test-run.pl
cd '/mysql/app/mysql//mysql-test' ; perl mysql-test-run.pl

Please report any problems at http://mariadb.org/jira

The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/

At this point, the MariaDB installation is complete

Post-setup

Join systemd management

# Copy systemd file
[root@node1 ~]# cp /mysql/app/mysql/support-files/systemd/mariadb.service /lib/systemd/system/

# Modify Startup Path
[root@node1 ~]# vim /lib/systemd/system/mariadb.service
ExecStart=/mysql/app/mysql/bin/mysqld $MYSQLD_OPTS $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION    

# Reload the systemd file
[root@node1 ~]# systemctl daemon-reload

Configuring environment variables (global)

# Add export PATH=$PATH:/mysql/app/mysql/bin/at the end of/etc/profile
[root@node1 ~]# vi /etc/profile.d/mysql.sh
# set mysql environment
export PATH=$PATH:/mysql/app/mysql/bin/

# Reload/etc/profile
[root@node1 ~]# source /etc/profile

Modify password and authorize

# Open mysql
[root@node1 ~]# systemctl start mariadb

# Log in to mysql
[root@node1 ~]# mysql -uroot -p
Enter password:  # No password required for first entry

# Set the root user's new password to qwert123..
MariaDB [(none)]> SET PASSWORD=PASSWORD("qwert123..");
Query OK, 0 rows affected (0.01 sec)

# Grant root login rights to all databases (tables) and all hosts to the user
MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'qwert123..' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)

# Refresh Permissions
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

CentOS 7 Compile and Install MySQL 5.7 (cmake)

Environmental Science

Host: CentOS Linux release 7.9.2009 (Core) Minimal Install

Install using the Linux - Generic TAR package

Mysql Compressed Pack Official Download Address: https://downloads.mysql.com/archives/community/

Select Version: 5.7.34
Select Operating System: Source Code
Select OS Version: Generic-Linux(Architecture Independent)
Download the Boost version from the list:

Compressed TAR Archive, Includes Boost Headers: mysql-boost-5.7.34.tar.gz

Get ready

Close firewall and selinux

systemctl stop firewalld
systemctl disable firewalld

setenforce 0
sed -i 's/=enforcing/=disabled/g' /etc/sysconfig/selinux

Uninstall the mariadb client that comes with the system

# View the Mariadb that comes with the system
[root@node1 ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
# Uninstall Mariadb from the system
[root@node1 ~]# rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64

Create Installation Path

# mysql program directory
[root@node1 ~]# mkdir -p /mysql/app/mysql
# mysql data directory
[root@node1 ~]# mkdir -p /mysql/data/3306
# mysql log directory
[root@node1 ~]# mkdir -p /mysql/log/3306

Create Users and Groups

# Create User Groups
[root@node1 ~]# groupadd -g 1001 mysql
# Create User
[root@node1 ~]# useradd -r -g mysql -s /bin/false -u 1001 mysql

install

Installation-related dependencies

[root@node1 ~]# yum -y install gcc gcc-c++ cmake bison bison-devel zlib-devel libcurl-devel libarchive-devel boost-devel   ncurses-devel gnutls-devel libxml2-devel openssl-devel libevent-devel libaio-devel perl-Data-Dumper

cmake description

One of the important features of cmake is its out-of-source-independent compilation function, that is, compilation can be done in another specified directory instead of the source directory, which guarantees that the source directory is not affected by any one compilation, so different compilations can occur multiple times in the same source tree, such as for different platforms

mysql compilation options: MySQL :: MySQL 5.7 Reference Manual :: 2.9.7 MySQL Source-Configuration Options

Download and unzip the source package

# Unzip Source Package
[root@node1 ~]# tar -zxvf mysql-boost-5.7.34.tar.gz  -C /mysql/app/
[root@node1 ~]# cp -av /mysql/app/mysql-5.7.34/boost/boost_1_59_0/boost /usr/local/boost


# Modify permissions
[root@node1 ~]# chown -R mysql:mysql /mysql

Compile and install mysql

[root@node1 ~]# cd /mysql/app/mysql-5.7.34/
[root@node1 mysql-5.7.34]# cmake . \
-DCMAKE_INSTALL_PREFIX=/mysql/app/mysql \
-DMYSQL_DATADIR=/data/mysql/ \
-DSYSCONFDIR=/etc/ \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_DEBUG=0 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_UNIX_ADDR=/mysql/data/3306/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/boost

[root@node1 mysql-5.7.34]# make && make install 



# If an error occurs, execute rm-f CMakeCache.txt before using cmake again

Create profile my.cnf

[root@node1 ~]# vi /mysql/data/3306/my.cnf
[mysql]
# set mysql client default chararter
default-character-set=utf8


[mysqld]
# set boot user
user=mysql
# set mysql server port  
port=3306
socket=/mysql/data/3306/mysql.sock
# set mysql install base dir
basedir=/mysql/app/mysql
# set the data store dir
datadir=/mysql/data/3306
# set the number of allow max connnection
max_connections=200
# set server charactre default encoding
character-set-server=utf8mb4
# the storage engine
default-storage-engine=INNODB
innodb_buffer_pool_size=200M
lower_case_table_names=1
max_allowed_packet=16M
explicit_defaults_for_timestamp=true
log-output=FILE
general_log=0
general_log_file=/myysql/log/3306/db-general.err
slow_query_log=ON
slow_query_log_file=/mysql/log/3306/db-query.err
long_query_time=10
log-error=/mysql/log/3306/db-error.err

# Create profile soft links
[root@node1 ~]# ln -sf /mysql/data/3306/my.cnf /etc/my.cnf

Initialization

[root@node1 ~]# /mysql/app/mysql/bin/mysqld --initialize --user=mysql --basedir=/mysql/app/mysql/ --datadir=/mysql/data/3306/
2021-09-12T22:14:07.736152Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-09-12T22:14:07.949340Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-09-12T22:14:07.983161Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-09-12T22:14:08.042472Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: bfbeb2ad-1416-11ec-9e61-000c292cc8f1.
2021-09-12T22:14:08.043095Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-09-12T22:14:08.298753Z 0 [Warning] CA certificate ca.pem is self signed.
2021-09-12T22:14:08.344078Z 1 [Note] A temporary password is generated for root@localhost: cRH_4?TNsLpP

Post-setup

Join systemd management

[root@node1 ~]# vi /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Community Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target


[Install]
WantedBy=multi-user.target
Alias=mysql.service


[Service]
User=mysql
Group=mysql
# Specify Type=forking to configure PID or specify daemonize to run
Type=forking

PermissionsStartOnly=true
ExecStart=/mysql/app/mysql/bin/mysqld --defaults-file=/mysql/data/3306/my.cnf --daemonize
LimitNOFILE = 65536
LimitNPROC = 65536 

# Reload the systemd file
[root@node1 ~]# systemctl daemon-reload

Configuring environment variables (global)

# Add export PATH=$PATH:/mysql/app/mysql/bin/at the end of/etc/profile
[root@node1 ~]# vi /etc/profile.d/mysql.sh
# set mysql environment
export PATH=$PATH:/mysql/app/mysql/bin/

# Reload/etc/profile
[root@node1 ~]# source /etc/profile

Modify password and authorize

# Open mysql
[root@node1 ~]# systemctl start mysqld

# Log in to mysql and enter the initialization password
[root@node1 ~]# mysql -uroot -p'cRH_4?TNsLpP'

# Set the root user's new password to qwert123..
mysql> SET PASSWORD=PASSWORD("qwert123..");
Query OK, 0 rows affected, 1 warning (0.00 sec)


# Grant root login rights to all databases (tables) and all hosts to the user
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'qwert123..' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)


# Refresh Permissions
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)


Tags: MySQL CentOS

Posted on Fri, 19 Nov 2021 14:06:24 -0500 by adamgeorge