源码编译并二进制安装MySQL5.7 3 二进制安装mariadb10.4
Posted njsummer
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了源码编译并二进制安装MySQL5.7 3 二进制安装mariadb10.4相关的知识,希望对你有一定的参考价值。
1、通过编译、二进制安装mysql5.7
简要说明:本次是在VMWare EsxI6.7+VCSA67的环境下,CentOS8.4虚拟服务器上完成的 Mysql5.7.36 源码编译安装实践。
1.1 源码准备
1.1.1 MySQL源码包及官网
官网下载链接:https://downloads.mysql.com/archives/community/
1.1.2 源码包
mysql-5.7.36.tar.gz
boost_1_59_0.tar.gz
rpcsvc-proto-1.4.tar.gz
1.2 编译环境准备
##### 依赖包说明
1 cmake
MySQL使用cmake跨平台工具预编译源码,用于设置mysql的编译参数。如:安装目录、数据存放目录、字符编码、排序规则等。安装最新版本即可。
2 make
mysql源代码是由C和C++语言编写,在linux下使用make对源码进行编译和构建,要求必须安装make 3.75或以上版本
3 gcc
GCC是Linux下的C语言编译工具,mysql源码编译完全由C和C++编写,要求必须安装GCC4.4.6或以上版本
4 Boost
mysql源码中用到了C++的Boost库,要求必须安装boost1.59.0或以上版本
5 bison
Linux下C/C++语法分析器
6> ncurses
字符终端处理库
##### 安装依赖包
[root@CentOS84 ]#
[root@CentOS84 ]#yum install -y gcc gcc-c++ bzip2-devel bzip2-libs bison libtirpc-devel ncurses ncurses-devel bison cmake perl-Data-Dumper
BaseOS 3.9 kB/s | 3.9 kB 00:00
AppStream 809 B/s | 4.3 kB 00:05
EPEL 33 kB/s | 4.7 kB 00:00
EPEL 8.3 MB/s | 11 MB 00:01
extras 18 kB/s | 1.5 kB 00:00
centosplus 1.7 kB/s | 1.5 kB 00:00
Package gcc-8.5.0-4.el8_5.x86_64 is already installed.
Package gcc-c++-8.5.0-4.el8_5.x86_64 is already installed.
Package bzip2-libs-1.0.6-26.el8.x86_64 is already installed.
Package ncurses-6.1-9.20180224.el8.x86_64 is already installed.
Package perl-Data-Dumper-2.167-399.el8.x86_64 is already installed.
Dependencies resolved.
................. #省略很多屏显内容,要注意验证确保所有的包被正确安装
Upgraded:
libtirpc-1.1.4-5.el8.x86_64
Installed:
bison-3.0.4-10.el8.x86_64 bzip2-devel-1.0.6-26.el8.x86_64 cmake-3.20.2-4.el8.x86_64 cmake-data-3.20.2-4.el8.noarch
cmake-filesystem-3.20.2-4.el8.x86_64 cmake-rpm-macros-3.20.2-4.el8.noarch libtirpc-devel-1.1.4-5.el8.x86_64 libuv-1:1.41.1-1.el8_4.x86_64
ncurses-c++-libs-6.1-9.20180224.el8.x86_64 ncurses-devel-6.1-9.20180224.el8.x86_64
Complete!
[root@CentOS84 ]#
##### 准备boost,Boost是为C++语言标准库提供扩展的一些C++程序库的总称。
[root@CentOS84 ]#cd /usr/local
[root@CentOS84 ]#wget http://downloads.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
[root@CentOS84 ]#tar xzf boost_1_59_0.tar.gz
[root@CentOS84 ]#ll
drwx------ 8 501 games 302 Aug 12 2015 boost_1_59_0
-rw-r--r-- 1 root root 83709983 Aug 13 2015 boost_1_59_0.tar.gz
#boost标准化命名
[root@CentOS84 ]#mv boost_1_59_0/ boost
[root@CentOS84 ]#ll
drwx------ 8 501 games 302 Aug 12 2015 boost
-rw-r--r-- 1 root root 83709983 Aug 13 2015 boost_1_59_0.tar.gz
[root@CentOS84 ]#
##### 安装rpcsvc: 如果不安装在cmake时候会报错
[root@CentOS84 ]#cd /usr/local
[root@CentOS84 ]#wget https://github.com/thkukuk/rpcsvc-proto/releases/download/v1.4/rpcsvc-proto-1.4.tar.gz
[root@CentOS84 ]#ll
-rw-r--r-- 1 root root 149354 Dec 8 12:40 rpcsvc-proto-1.4.tar.gz
[root@CentOS84 ]#tar xf rpcsvc-proto-1.4.tar.gz
[root@CentOS84 ]#cd rpcsvc-proto-1.4
#编译安装
[root@CentOS84 ]#./configure && make -j 16 && make install
configure: loading site script /usr/share/config.site
checking for a BSD-compatible install... /usr/bin/install -c
............. # 省略部分屏显过程内容
make[2]: Leaving directory /usr/local/rpcsvc-proto-1.4
make[1]: Leaving directory /usr/local/rpcsvc-proto-1.4
[root@CentOS84 ]#
1.3 MySQL编译安装
##### 下载并解压源码包
[root@CentOS84 ]#cd /usr/local/src/
[root@CentOS84 ]#wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.36.tar.gz
[root@CentOS84 ]#ll /usr/local/src/
total 54924
-rw-r--r-- 1 root root 56238341 Feb 7 17:23 mysql-5.7.36.tar.gz
[root@CentOS84 ]#tar -zxvf mysql-5.7.36.tar.gz
[root@CentOS84 ]#cd /usr/local/src/mysql-5.7.36
##### 创建规划好的目录
[root@CentOS84 ]#mkdir -p /data/mysql/data
[root@CentOS84 ]#mkdir -p /data/mysql/log/
[root@CentOS84 ]#mkdir -p /data/mysql/binlog/
[root@CentOS84 ]#mkdir -p /data/mysql/tmp/
[root@CentOS84 ]#ll /data/mysql/
total 0
drwxr-xr-x 2 root root 6 Feb 8 14:38 binlog
drwxr-xr-x 2 root root 6 Feb 8 14:38 data
drwxr-xr-x 2 root root 6 Feb 8 14:38 log
drwxr-xr-x 2 root root 6 Feb 8 14:38 tmp
[root@CentOS84 ]#
##### cmake配置编译参数
[root@CentOS84 ]#cmake . \\
> -DCMAKE_INSTALL_PREFIX=/usr/local/mysql57 \\
> -DSYSCONFDIR=/etc \\
> -DMYSQL_DATADIR=/data/mysql/data \\
> -DMYSQL_UNIX_ADDR=/data/mysql/tmp/mysql.sock \\
> -DDEFAULT_CHARSET=utf8 \\
> -DDEFAULT_COLLATION=utf8_general_ci \\
> -DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \\
> -DENABLED_LOCAL_INFILE=ON \\
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \\
> -DWITH_FEDERATED_STORAGE_ENGINE=1 \\
> -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \\
> -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \\
> -DWITHOUT_PARTITION_STORAGE_ENGINE=1 \\
> -DWITH_ZLIB=bundled \\
> -DWITH_EMBEDDED_SERVER=1 \\
> -DWITH_DEBUG=0 \\
> -DWITH_SYSTEMD=1 \\
> -DWITH_BOOST=/usr/local/boost
# 回车后屏幕不停滚屏,出现如下内容
CMake Deprecation Warning at CMakeLists.txt:30 (CMAKE_MINIMUM_REQUIRED):
Compatibility with CMake < 2.8.12 will be removed from a future version of
CMake.
..................... #省略很多内容,务必耐性等待
-- Configuring done #
-- Generating done
-- Build files have been written to: /usr/local/src/mysql-5.7.36
[root@CentOS84 ]#
[root@CentOS84 ]#make -j 16 && make install
[ 0%] Building C object CMakeFiles/lz4_lib.dir/extra/lz4/lz4-1.9.3/lz4.c.o
[ 0%] makelist -bh /usr/local/src/mysql-5.7.36/extra/libedit/libedit-20191231-3.1/src/vi.c /usr/local/src/mysql-5.7.36/extra/libedit/libedit-20191231-3.1/src/emacs.c /usr/local/src/mysql-5.7.36/extra/libedit/libedit-20191231-3.1/src/common.c > help.h
[ 0%] makelist -h /usr/local/src/mysql-5.7.36/extra/libedit/libedit-20191231-3.1/src/emacs.c > emacs.h
[ 0%] Building C object vio/CMakeFiles/vio.dir/vio.c.o
[ 0%] Building C object strings/CMakeFiles/strings.dir/bchange.c.o
...................#中间省略部分屏显内容,这个过程和下面编译过程快慢取决于CPU个数和内存,不报错不要终止运行,耐心等待
-- Installing: /usr/local/mysql57/share/aclocal/mysql.m4
-- Installing: /usr/local/mysql57/support-files/mysql.server
[root@CentOS84 ]#
1.4 MySQL运行环境及变量设置
##### 创建组并授权
[root@CentOS84 ]#groupadd mysql
[root@CentOS84 ]#useradd mysql -s /sbin/nologin -M -g mysql
[root@CentOS84 ]#chown -R mysql.mysql /data/mysql/
[root@CentOS84 ]#
##### 配置MySQL环境变量,并使之生效
[root@CentOS84 ]#echo export PATH=/usr/local/src/mysql57/bin:$PATH >>/etc/profile
[root@CentOS84 ]#tail -1 /etc/profile
export PATH=/usr/local/src/mysql57/bin:$PATH
[root@CentOS84 ]#export PATH=/usr/local/src/mysql/bin:$PATH
[root@CentOS84 ]#source /etc/profile
[root@CentOS84 ]#
##### 创建数据库服务配置文件my.cnf 版本5.6之前有模板文件,5.7版本support-files目录下没有.cnf参考文件,需自己创建
[root@CentOS84 ]#vim /etc/my.cnf
[root@CentOS84 ]#cat /etc/my.cnf
[client]
port = 3306
socket = /data/mysql/tmp/mysql.sock
default-character-set = utf8
[mysqld]
port = 3306
user = mysql
basedir = /usr/local/mysql57
datadir = /data/mysql/data
pid-file = /data/mysql/tmp/mysql.pid
socket = /data/mysql/tmp/mysql.sock
tmpdir = /data/mysql/tmp
character_set_server = utf8
server-id = 1
max_connections = 1000
max_connect_errors = 15
sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
log-bin = /data/mysql/binlog/mysql-bin
log-error = /data/mysql/log/mysql-error.log
[root@CentOS84 ]#
##### 创建PID目录并授权
[root@CentOS84 ]#mkdir -p /var/run/mysqld
[root@CentOS84 ]#chown mysql.mysql /var/run/mysqld
##### 初始化数据库,注意目录要规划好并相互匹配好
[root@CentOS84 ]#/usr/local/mysql57/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql57 --datadir=/data/mysql/data
##### 创建开机启动服务文件
[root@CentOS84 ]#cp /usr/local/mysql57/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
[root@CentOS84 ]#vim /usr/lib/systemd/system/mysqld.service
[root@CentOS84 ]#cat /usr/lib/systemd/system/mysqld.service
# Copyright (c) 2015, 2021, Oracle and/or its affiliates.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation. The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License, version 2.0, for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# systemd service file for MySQL forking server
#
[Unit]
Description=MySQL 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
[Service]
User=mysql
Group=mysql
Type=forking
PIDFile=/data/mysql/tmp/mysql.pid #注:这行是需要修改的内容
# Disable service start and stop timeout logic of systemd for mysqld service.
TimeoutSec=0
# Execute pre and post scripts as root
PermissionsStartOnly=true
# Needed to create system tables
ExecStartPre=/usr/local/mysql57/bin/mysqld_pre_systemd
# Start main service
ExecStart=/usr/local/mysql57/bin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS
# Use this to switch malloc implementation
EnvironmentFile=-/etc/sysconfig/mysql
# Sets open_files_limit
LimitNOFILE = 5000
Restart=on-failure
RestartPreventExitStatus=1
PrivateTmp=false
[root@CentOS84 ]#
##### 启动MySQL服务
[root@CentOS84 ]#ss -tln
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:111 0.0.0.0:*
LISTEN 0 32 192.168.122.1:53 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 5 127.0.0.1:631 0.0.0.0:*
LISTEN 0 128 [::]:111 [::]:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 5 [::1]:631 [::]:*
[root@CentOS84 ]#
[root@CentOS84 ]#systemctl daemon-reload
[root@CentOS84 ]#systemctl enable mysqld.service
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
#注:后台启动mysql服务
[root@CentOS84 ]#systemctl start mysqld &
[root@CentOS84 ]#ss -tln
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:111 0.0.0.0:*
LISTEN 0 32 192.168.122.1:53 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 5 127.0.0.1:631 0.0.0.0:*
LISTEN 0 250 *:3306 *:*
LISTEN 0 128 [::]:111 [::]:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 5 [::1]:631 [::]:*
##### 管理MySQL账号:授权、创建本地管理帐号及删除无密&码帐号
[root@CentOS84 ]#/usr/local/mysql57/bin/mysqladmin -u root password shone2022
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety. #注:这个警告是mysql自带的,告诉你在屏幕上直接输入mysql密&码并显示是不安全的。
[root@CentOS84 ]#/usr/local/mysql57/bin/mysql -uroot -pshone2022 -e "delete from mysql.user where password=;"
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1054 (42S22) at line 1: Unknown column password in where clause
[root@CentOS84 ]#/usr/local/mysql57/bin/mysql -uroot -pshone2022 -e "flush privileges;"
mysql: [Warning] Using a password on the command line interface can be insecure.
1.5 MySQL验证及测试连接
##### 管理员账户登录数据库
[root@CentOS84 ]#/usr/local/mysql57/bin/mysql -uroot -pshone2022
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \\g.
Your MySQL connection id is 5
Server version: 5.7.36-log Source distribution
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type help; or \\h for help. Type \\c to clear the current input statement.
##### 创建一个shone新账号,并授权
mysql> create user shone@% identified by 12345678;
Query OK, 0 rows affected (0.01 sec)
mysql> grant all privileges on *.* to shone@%;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
##### 查看mysql5.7 默认表
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
##### 创建一个名为mytestdb1新表
mysql> create database mytestdb1;
Query OK, 1 row affected (0.01 sec)
mysql> show create database mytestdb1;
+-----------+--------------------------------------------------------------------+
| Database | Create Database |
+-----------+--------------------------------------------------------------------+
| mytestdb1 | CREATE DATABASE "mytestdb1" /*!40100 DEFAULT CHARACTER SET utf8 */ |
+-----------+--------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| mytestdb1 |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.01 sec)
mysql> quit
Bye
[root@CentOS84 ]#
##### 用shone账户登录数据库
[root@CentOS84 ]#/usr/local/mysql57/bin/mysql -ushone -p
Enter password: 12345678
Welcome to the MySQL monitor. Commands end with ; or \\g.
Your MySQL connection id is 8
Server version: 5.7.36-log Source distribution
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type help; or \\h for help. Type \\c to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| mytestdb1 |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
mysql>
##### 创建软链接,这样不需要带绝对路径直接管理和操作mysql数据库 (这个方法常被用于替代修改环境变量的方法)
[root@CentOS84 ]#ln -s /usr/local/mysql57/bin/mysql /usr/bin
[root@CentOS84 ]#cp /usr/local/mysql57/bin/my_print_defaults /usr/bin
[root@CentOS84 ]#ll /usr/local/mysql57/bin/my_print_defaults
-rwxr-xr-x 1 root root 6123896 Feb 8 14:54 /usr/local/mysql57/bin/my_print_defaults
[root@CentOS84 ]#ll /usr/bin/my_print_defaults
-rwxr-xr-x 1 root root 6123896 Feb 9 00:17 /usr/bin/my_print_defaults
[root@CentOS84 ]#
##### 创建好软链接后,直接输入mysql就可以管理和增删改查数据库了。
[root@CentOS84 ]#mysql -ushone -p
Enter password: 12345678
Welcome to the MySQL monitor. Commands end with ; or \\g.
Your MySQL connection id is 9
Server version: 5.7.36-log Source distribution
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type help; or \\h for help. Type \\c to clear the current input statement.
mysql>
##### 数据库status信息
[root@CentOS84 ]#mysql -uroot -pshone2022
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \\g.
Your MySQL connection id is 9
Server version: 5.7.36-log Source distribution
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type help; or \\h for help. Type \\c to clear the current input statement.
mysql> status
--------------
mysql Ver 14.14 Distrib 5.7.36, for Linux (x86_64) using EditLine wrapper
Connection id: 9
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile:
Using delimiter: ;
Server version: 5.7.36-log Source distribution
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /data/mysql/tmp/mysql.sock
Uptime: 10 hours 33 min 25 sec
Threads: 1 Questions: 33 Slow queries: 0 Opens: 126 Flush tables: 1 Open tables: 119 Queries per second avg: 0.000
--------------
mysql>
1.6 附录
1.6.1 硬件和操作系统详细信息
[root@CentOS84 ]#cat /proc/version
Linux version 4.18.0-305.3.1.el8.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 8.4.1 20200928 (Red Hat 8.4.1-1) (GCC)) #1 SMP Tue Jun 1 16:14:33 UTC 2021
[root@CentOS84 ]#cat /etc/redhat-release
CentOS Linux release 8.4.2105
[root@CentOS84 ]#lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 16 # 这个值在编译时候需要用到,个数越多编译越快
On-line CPU(s) list: 0-15
Thread(s) per core: 1
Core(s) per socket: 1
Socket(s): 16
NUMA node(s): 2
Vendor ID: GenuineIntel
Bios Vendor ID: GenuineIntel
CPU family: 6
Model: 79
Model name: Intel(R) Xeon(R) CPU E7-4809 v4 @ 2.10GHz
BIOS Model name: Intel(R) Xeon(R) CPU E7-4809 v4 @ 2.10GHz
Stepping: 1
CPU MHz: 2094.952
BogoMIPS: 4189.90
Hypervisor vendor: VMware
Virtualization type: full
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 20480K
NUMA node0 CPU(s): 0-7
NUMA node1 CPU(s): 8-15
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc cpuid pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch cpuid_fault invpcid_single pti ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap xsaveopt arat md_clear flush_l1d arch_capabilities
[root@CentOS84 ]#
[root@CentOS84 ]#free -m
total used free shared buff/cache available
Mem: 31956 802 22624 17 8530 30680
Swap: 4095 0 4095
[root@CentOS84 ]#
[root@CentOS84 ]#lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 200M 0 part /boot/efi
├─sda2 8:2 0 100G 0 part /
├─sda3 8:3 0 4G 0 part [SWAP]
└─sda4 8:4 0 50G 0 part /data
sr0 11:0 1 1024M 0 rom
[root@CentOS84 ]#
#### 配置好NTP,同步服务器时间
[root@CentOS84 ]#systemctl enable --now chronyd.service
Created symlink /etc/systemd/system/multi-user.target.wants/chronyd.service → /usr/lib/systemd/system/chronyd.service.
[root@CentOS84 ]#date
Mon Feb 7 17:45:23 CST 2022
[root@CentOS84 ]#
1.6.2 ERROR 1054 (42S22)问题解决
##### 在管理MySQL账号:授权、创建本地管理帐号及删除无密&码帐号章节内的错误及解决方法
[root@CentOS84 ]#/usr/local/mysql57/bin/mysqladmin -u root password shone2022
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
# 注:这个警告是mysql自带的,告诉你在屏幕上直接输入mysql密&码并显示是不安全的。
[root@CentOS84 ]#/usr/local/mysql57/bin/mysql -uroot -pshone2022 -e "delete from mysql.user where password=;"
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1054 (42S22) at line 1: Unknown column password in where clause
# 注:这个错误解决方法 https://blog.csdn.net/qq1966058819/article/details/104572910
# 原因分析:这是在做启动mysql的一个root账户检查,但是由于5.7以后mysql.user表中的password字段被修改为了authentication_string,但是这个sql语句并没有更改,所以报错......
# 解决办法:就是找到这个sql语句,将其中的password 改为authentication_string 就可以了
1.6.3 Could not find rpcgen问题解决
#### 如果不提前安装好rpcsvc-proto-1.4.tar.gz,会有下面出错信息
-- Performing Test X_PUTLONG_NOT_USE_CONST - Failed
CMake Error at rapid/plugin/group_replication/rpcgen.cmake:100 (MESSAGE):
Could not find rpcgen
Call Stack (most recent call first):
rapid/plugin/group_replication/CMakeLists.txt:36 (INCLUDE)
-- Configuring incomplete, errors occurred!
See also "/usr/local/src/mysql-5.7.29/CMakeFiles/CMakeOutput.log".
See also "/usr/local/src/mysql-5.7.29/CMakeFiles/CMakeError.log".
rm -f CMakeCache.txt #注:如果cmake失败要记得运行此条命令
##### 解决方案
安装rpcsvc的包:
[root@ecs-c13b mysql-8.0.11]# wget https://github.com/thkukuk/rpcsvc-proto/releases/download/v1.4/rpcsvc-proto-1.4.tar.gz
编译安装
[root@ecs-c13b mysql-8.0.11]# tar xf rpcsvc-proto-1.4.tar.gz
[root@ecs-c13b mysql-8.0.11]# cd rpcsvc-proto-1.4
[root@ecs-c13b rpcsvc-proto-1.4]# ./configure && make -j 4 && make install
再次运行上面cmake那段命令,后再运行下面make命令
make -j 16 && make install
1.6.4 参考资料
参考文档: 中文开源技术交流社区 https://my.oschina.net/u/938331/blog/3166180
特别感谢:在本人IT职业生涯中,经常在网上查询到很多倾注原作者心血和汗水的美文,并从中获取到解决问题的方法和灵感,在此一并表示感谢。
2、二进制安装mariadb10.4
2.1 源码准备
2.1.1 mariadb源码包及官网
https://mariadb.com/downloads/
2.1.2 源码包
mariadb-10.4.22-linux-x86_64.tar.gz
2.2 安装准备
#校正主机时间
[root@CentOS84 ]#systemctl enable --now chronyd.service
Created symlink /etc/systemd/system/multi-user.target.wants/chronyd.service → /usr/lib/systemd/system/chronyd.service.
[root@CentOS84 ]#date
Tue Feb 8 19:34:34 CST 2022
[root@CentOS84 ]#
[root@CentOS84 ]#uname -a
Linux CentOS84 4.18.0-305.3.1.el8.x86_64 #1 SMP Tue Jun 1 16:14:33 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
[root@CentOS84 ]#
#根据上面的硬件信息下载相应的二进制安装包。需要说明的是这个安装包完成安装后没有mariadb.service文件,直接用systenctl start mariadb.service启动数据库和设定开机启动。可以通过 wget https://mirrors.aliyun.com/mariadb//mariadb-10.4.22/bintar-linux-systemd-x86_64/mariadb-10.4.22-linux-systemd-x86_64.tar.gz下载到相应的二进制包,经过安装实践完全可用,但是本文将继续采用官方的安装包完成,可借用mariadb.service文件,实现systemd管理mariadb的启动、开机自启和停止等。
[root@CentOS84 ]#cd /usr/local/
[root@CentOS84 ]#wget https://dlm.mariadb.com/1902423/MariaDB/mariadb-10.4.22/bintar-linux-x86_64/mariadb-10.4.22-linux-x86_64.tar.gz
[root@CentOS84 ]#ll
total 1121740
drwxr-xr-x. 2 root root 25 Dec 28 01:09 bin
drwxr-xr-x. 2 root root 6 Nov 3 2020 etc
drwxr-xr-x. 2 root root 6 Nov 3 2020 games
drwxr-xr-x. 2 root root 6 Nov 3 2020 include
drwxr-xr-x. 2 root root 6 Nov 3 2020 lib
drwxr-xr-x. 3 root root 17 Nov 17 20:09 lib64
drwxr-xr-x. 2 root root 6 Nov 3 2020 libexec
-rw-r--r-- 1 root root 1148661449 Jan 27 09:44 mariadb-10.4.22-linux-x86_64.tar.gz
drwxr-xr-x. 2 root root 6 Nov 3 2020 sbin
drwxr-xr-x. 5 root root 49 Nov 17 20:09 share
drwxr-xr-x. 2 root root 6 Feb 8 20:27 src
[root@CentOS84 ]#
#解压二进制安装包
[root@CentOS84 ]#tar -zxvpf mariadb-10.4.22-linux-x86_64.tar.gz
[root@CentOS84 ]#ll
total 1121740
drwxrwxr-x 12 summer summer 257 Nov 7 01:00 mariadb-10.4.22-linux-x86_64
-rw-r--r-- 1 root root 1148661449 Jan 27 09:44 mariadb-10.4.22-linux-x86_64.tar.gz
[root@CentOS84 ]#
#按照官网上安装手册或者二进制包解压后的INSTALL-BINARY文件,创建软链接
[root@CentOS84 ]#ln -s mariadb-10.4.22-linux-x86_64 mysql
[root@CentOS84 ]#ll
total 1121740
drwxrwxr-x 12 summer summer 257 Nov 7 01:00 mariadb-10.4.22-linux-x86_64
-rw-r--r-- 1 root root 1148661449 Jan 27 09:44 mariadb-10.4.22-linux-x86_64.tar.gz
lrwxrwxrwx 1 root root 28 Feb 8 20:38 mysql -> mariadb-10.4.22-linux-x86_64
[root@CentOS84 ]#
2.3 mariadb配置及初始化
2.3.1 数据库的基本配置
#创建组及用户
[root@CentOS84 ]#groupadd mysql
[root@CentOS84 ]#useradd -s /sbin/nologin -r -g mysql mysql
#新建数据目录与权限
[root@CentOS84 ]#mkdir /data/mariadb -p
[root@CentOS84 ]#chown root.root /data/mariadb -R
[root@CentOS84 ]#mkdir /etc/my.cnf.d/
#配置my.cnf
[root@CentOS84 ]#vim /etc/my.cnf
[root@CentOS84 ]#cat /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql/
datadir=/data/mariadb
port=3306
socket=/data/mariadb/mysql.sock
symbolic-links=0
pid-file=/data/mariadb/pid/mariadb.pid
[mysqld_safe]
log-error=/data/mariadb/log/mariadb.log
[client]
port=3306
socket=/data/mariadb/mysql.sock
default-character-set=utf8
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
[root@CentOS84 ]#
2.3.2 初始化数据库
#数据库初始化
[root@CentOS84 ]#/usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --user=mysql --basedir=/usr/local/mysql --datadir=/data/mariadb
Installing MariaDB/MySQL system tables in /data/mariadb ...
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 /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe --datadir=/data/mariadb
You can test the MariaDB daemon with mysql-test-run.pl
cd /usr/local/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 MariaDBs strong and vibrant community:
https://mariadb.org/get-involved/
[root@CentOS84 ]#
[root@CentOS84 ]#mkdir /data/mariadb/log,pid
[root@CentOS84 ]#chown mysql.mysql -R /data/mariadb
[root@CentOS84 ]#ll -h /data/mariadb
total 109M
-rw-rw---- 1 mysql mysql 24K Feb 8 20:55 aria_log.00000001
-rw-rw---- 1 mysql mysql 52 Feb 8 20:55 aria_log_control
-rw-rw---- 1 mysql mysql 972 Feb 8 20:55 ib_buffer_pool
-rw-rw---- 1 mysql mysql 12M Feb 8 20:55 ibdata1
-rw-rw---- 1 mysql mysql 48M Feb 8 20:55 ib_logfile0
-rw-rw---- 1 mysql mysql 48M Feb 8 20:55 ib_logfile1
drwxr-xr-x 2 mysql mysql 6 Feb 8 21:19 log
drwx------ 2 mysql mysql 4.0K Feb 8 20:55 mysql
drwx------ 2 mysql mysql 20 Feb 8 20:55 performance_schema
drwxr-xr-x 2 mysql mysql 6 Feb 8 21:19 pid
drwx------ 2 mysql mysql 20 Feb 8 20:55 test
[root@CentOS84 ]#
#软链接,否则会报错错误提示
[root@CentOS84 ]#ln -s /data/mariadb/mysql.sock /tmp/mysql.sock
[root@CentOS84 ]#/usr/local/mysql/bin/mysqld_safe --user=mysql &
[root@CentOS84 ]#ss -tln
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 80 *:3306 *:*
#必须先让mariadb运行起来,才能对之进行安全初始化
[root@CentOS84 ]#/usr/local/mysql/bin/mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, well need the current
password for the root user. If youve just installed MariaDB, and
havent set the root password yet, you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.
You already have your root account protected, so you can safely answer n.
Switch to unix_socket authentication [Y/n] n
... skipping.
You already have your root account protected, so you can safely answer n.
Change the root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from localhost. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
... Success!
By default, MariaDB comes with a database named test that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If youve completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
[root@CentOS84 ]#
2.3.3 数据库开机启动
##### 本次安装用官网不带systemd的二进制包,因此不用systemctl方式实现开机启动mariadb。要实现systemctl开机自启,可以下载mariadb-10.4.22-linux-systemd-x86_64.tar.gz安装包,或者自行编写借用mariadb.service实现。
# 停数据库
[root@CentOS84 ]#/usr/local/mysql/bin/mysqladmin -uroot -p shutdown
Enter password:
[1]+ Done /usr/local/mysql/bin/mysqld_safe --user=mysql
[root@CentOS84 ]#
# 配置开机启动
[root@CentOS84 ]#ll /etc/rc.local
lrwxrwxrwx 1 root root 13 Dec 22 04:08 /etc/rc.local -> rc.d/rc.local
[root@CentOS84 ]#vim /etc/rc.local
[root@CentOS84 ]#cat /etc/rc.local
#!/bin/bash
touch /var/lock/subsys/local
# 下面行是增加的开机启动命令行
/usr/local/mysql/support-files/mysql.server start
[root@CentOS84 ]#
[root@CentOS84 ]#chmod a+x /etc/rc.d/rc.local
[root@CentOS84 ]#ll /etc/rc.d/rc.local
-rwxr-xr-x. 1 root root 523 Feb 9 00:17 /etc/rc.d/rc.local
[root@CentOS84 ]#ss -tln
[root@CentOS84 ]#reboot
[root@CentOS84 ]#ss -tln
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 80 *:3306 *:*
[root@CentOS84 ]#
[root@CentOS84 ]#/usr/local/mysql/bin/mysql
Welcome to the MariaDB monitor. Commands end with ; or \\g.
Your MariaDB connection id is 9
Server version: 10.4.22-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type help; or \\h for help. Type \\c to clear the current input statement.
MariaDB [(none)]> quit
Bye
##### 验证重启虚拟机,开机后服务器的3306端口监听正常
2.3.4 数据库环境变量设置
##### 配置环境变量(方法一)
[root@CentOS84 ]#mysql
bash: mysql: command not found... #mysql路径未写入path
Packages providing this file are:
mariadb
mysql
[root@CentOS84 ]#echo "PATH=/usr/local/mysql/bin:$PATH" >/etc/profile.d/mariadb.sh
[root@CentOS84 ]#chmod +x /etc/profile.d/mariadb.sh
[root@CentOS84 ]#source /etc/profile.d/mariadb.sh
[root@CentOS84 ]#cat /etc/profile.d/mariadb.sh
PATH=/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@CentOS84 ]#mysql
Welcome to the MariaDB monitor. Commands end with ; or \\g.
Your MariaDB connection id is 9
Server version: 10.4.22-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type help; or \\h for help. Type \\c to clear the current input statement.
MariaDB [(none)]>
MariaDB [(none)]> quit
[root@CentOS84 ]#reboot
##### 软链接(方法二)
[root@CentOS84 ]#ln -s /usr/local/mysql/bin/mysql /usr/bin
##### 重启虚拟机验证也是正常生效了,至此所有的安装工作完成。数据库的基本设置、简单操作就不再赘述。
2.4 附录
2.4.1 参考资料
参考文档: Centos7.6二进制安装mariadb10.4.11 https://blog.csdn.net/php_dandan/article/details/103584166
Centos7安装配置mariadb10.4.13(二进制)https://blog.csdn.net/oToyix/article/details/106568128
特别感谢:在本人IT职业生涯中,经常在网上查询到很多倾注原作者心血和汗水的美文,并从中获取到解决问题的方法和灵感,在此一并表示感谢。
以上是关于源码编译并二进制安装MySQL5.7 3 二进制安装mariadb10.4的主要内容,如果未能解决你的问题,请参考以下文章
Mysql系列二:Centos7.4安装mysql5.7.28源码