源码编译并二进制安装MySQL5.7 3二进制安装mariadb10.4

别裁伪体亲风雅,转益多师是汝师。这篇文章主要讲述源码编译并二进制安装MySQL5.7 3二进制安装mariadb10.4相关的知识,希望能为你提供帮助。
1、通过编译、二进制安装mysql5.7简要说明:本次是在VMWare EsxI6.7+VCSA67的环境下,CentOS8.4虚拟服务器上完成的 Mysql5.7.36 源码编译安装实践。
1.1源码准备
1.1.1MySQL源码包及官网官网下载链接:https://downloads.mysql.com/archives/community/

源码编译并二进制安装MySQL5.7 3二进制安装mariadb10.4

文章图片

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 bisonlibtirpc-devel ncurses ncurses-devel bison cmake perl-Data-Dumper BaseOS3.9 kB/s | 3.9 kB00:00 AppStream809B/s | 4.3 kB00:05 EPEL33 kB/s | 4.7 kB00:00 EPEL8.3 MB/s |11 MB00:01 extras18 kB/s | 1.5 kB00:00 centosplus1.7 kB/s | 1.5 kB00: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_64bzip2-devel-1.0.6-26.el8.x86_64cmake-3.20.2-4.el8.x86_64cmake-data-3.20.2-4.el8.noarch cmake-filesystem-3.20.2-4.el8.x86_64cmake-rpm-macros-3.20.2-4.el8.noarchlibtirpc-devel-1.1.4-5.el8.x86_64libuv-1:1.41.1-1.el8_4.x86_64 ncurses-c++-libs-6.1-9.20180224.el8.x86_64ncurses-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------8501 games302 Aug 122015 boost_1_59_0 -rw-r--r--1 root root83709983 Aug 132015 boost_1_59_0.tar.gz #boost标准化命名 [root@CentOS84 ]#mv boost_1_59_0/ boost [root@CentOS84 ]#ll drwx------8501 games302 Aug 122015 boost -rw-r--r--1 root root83709983 Aug 132015 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 root149354 Dec8 12:40 rpcsvc-proto-1.4.tar.gz [root@CentOS84 ]#tar xf rpcsvc-proto-1.4.tar.gz [root@CentOS84 ]#cdrpcsvc-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.3MySQL编译安装
##### 下载并解压源码包 [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 Feb7 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 Feb8 14:38 binlog drwxr-xr-x 2 root root 6 Feb8 14:38 data drwxr-xr-x 2 root root 6 Feb8 14:38 log drwxr-xr-x 2 root root 6 Feb8 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.4MySQL运行环境及变量设置
##### 创建组并授权 [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, MA02110-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 StateRecv-QSend-QLocal Address:PortPeer Address:PortProcess LISTEN01280.0.0.0:1110.0.0.0:* LISTEN032192.168.122.1:530.0.0.0:* LISTEN01280.0.0.0:220.0.0.0:* LISTEN05127.0.0.1:6310.0.0.0:* LISTEN0128[::]:111[::]:* LISTEN0128[::]:22[::]:* LISTEN05[::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 StateRecv-QSend-QLocal Address:PortPeer Address:PortProcess LISTEN01280.0.0.0:1110.0.0.0:* LISTEN032192.168.122.1:530.0.0.0:* LISTEN01280.0.0.0:220.0.0.0:* LISTEN05127.0.0.1:6310.0.0.0:* LISTEN0250*:3306*:* LISTEN0128[::]:111[::]:* LISTEN0128[::]:22[::]:* LISTEN05[::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 Feb8 14:54 /usr/local/mysql57/bin/my_print_defaults [root@CentOS84 ]#ll /usr/bin/my_print_defaults -rwxr-xr-x 1 root root 6123896 Feb9 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 -------------- mysqlVer 14.14 Distrib 5.7.36, for Linux (x86_64) usingEditLine 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 Dbcharacterset:utf8 Client characterset:utf8 Conn.characterset:utf8 UNIX socket:/data/mysql/tmp/mysql.sock Uptime:10 hours 33 min 25 secThreads: 1Questions: 33Slow queries: 0Opens: 126Flush tables: 1Open tables: 119Queries 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 totalusedfreesharedbuff/cacheavailable Mem:319568022262417853030680 Swap:409504095 [root@CentOS84 ]#[root@CentOS84 ]#lsblk NAMEMAJ:MIN RMSIZE RO TYPE MOUNTPOINT sda8:00200G0 disk ├─sda18:10200M0 part /boot/efi ├─sda28:20100G0 part / ├─sda38:304G0 part [SWAP] └─sda48:4050G0 part /data sr011:01 1024M0 rom [root@CentOS84 ]##### 配置好NTP,同步服务器时间 [root@CentOS84 ]#systemctl enable --nowchronyd.service Created symlink /etc/systemd/system/multi-user.target.wants/chronyd.service → /usr/lib/systemd/system/chronyd.service. [root@CentOS84 ]#date Mon Feb7 17:45:23 CST 2022 [root@CentOS84 ]#

1.6.2ERROR 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.3Could 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]# cdrpcsvc-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.1mariadb源码包及官网https://mariadb.com/downloads/
【源码编译并二进制安装MySQL5.7 3二进制安装mariadb10.4】
源码编译并二进制安装MySQL5.7 3二进制安装mariadb10.4

文章图片

2.1.2源码包
mariadb-10.4.22-linux-x86_64.tar.gz

2.2安装准备
#校正主机时间 [root@CentOS84 ]#systemctl enable --nowchronyd.service Created symlink /etc/systemd/system/multi-user.target.wants/chronyd.service → /usr/lib/systemd/system/chronyd.service. [root@CentOS84 ]#date Tue Feb8 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 root25 Dec 28 01:09 bin drwxr-xr-x. 2 root root6 Nov32020 etc drwxr-xr-x. 2 root root6 Nov32020 games drwxr-xr-x. 2 root root6 Nov32020 include drwxr-xr-x. 2 root root6 Nov32020 lib drwxr-xr-x. 3 root root17 Nov 17 20:09 lib64 drwxr-xr-x. 2 root root6 Nov32020 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 root6 Nov32020 sbin drwxr-xr-x. 5 root root49 Nov 17 20:09 share drwxr-xr-x. 2 root root6 Feb8 20:27 src [root@CentOS84 ]##解压二进制安装包 [root@CentOS84 ]#tar -zxvpf mariadb-10.4.22-linux-x86_64.tar.gz [root@CentOS84 ]#ll total 1121740 drwxrwxr-x12 summer summer257 Nov7 01:00 mariadb-10.4.22-linux-x86_64 -rw-r--r--1 rootroot1148661449 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-x12 summer summer257 Nov7 01:00 mariadb-10.4.22-linux-x86_64 -rw-r--r--1 rootroot1148661449 Jan 27 09:44 mariadb-10.4.22-linux-x86_64.tar.gz lrwxrwxrwx1 rootroot28 Feb8 20:38 mysql -> mariadb-10.4.22-linux-x86_64 [root@CentOS84 ]#

2.3mariadb配置及初始化
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 mysql24K Feb8 20:55 aria_log.00000001 -rw-rw---- 1 mysql mysql52 Feb8 20:55 aria_log_control -rw-rw---- 1 mysql mysql972 Feb8 20:55 ib_buffer_pool -rw-rw---- 1 mysql mysql12M Feb8 20:55 ibdata1 -rw-rw---- 1 mysql mysql48M Feb8 20:55 ib_logfile0 -rw-rw---- 1 mysql mysql48M Feb8 20:55 ib_logfile1 drwxr-xr-x 2 mysql mysql6 Feb8 21:19 log drwx------ 2 mysql mysql 4.0K Feb8 20:55 mysql drwx------ 2 mysql mysql20 Feb8 20:55 performance_schema drwxr-xr-x 2 mysql mysql6 Feb8 21:19 pid drwx------ 2 mysql mysql20 Feb8 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 StateRecv-QSend-QLocal Address:PortPeer Address:PortProcess LISTEN080*: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 Feb9 00:17 /etc/rc.d/rc.local [root@CentOS84 ]#ss -tln [root@CentOS84 ]#reboot [root@CentOS84 ]#ss -tln StateRecv-QSend-QLocal Address:PortPeer Address:PortProcess LISTEN080*: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 ServerCopyright (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 ServerCopyright (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职业生涯中,经常在网上查询到很多倾注原作者心血和汗水的美文,并从中获取到解决问题的方法和灵感,在此一并表示感谢。

    推荐阅读