centOS8源码编译安装mysql8.0

centOS8.3源码编译安装mysql8.0.19

由于笔者在配置过程中遇到了各种问题,还尝试了centOS8.2、centOS7等不同版本的源码编译,出现了编译过程中卡到72%、88%等各种问题,这篇会给出一个很详细的教程以及常见问题和如何解决。当然,个人建议如果不爱折腾还是考虑用宝塔面板直接安装吧。

如何使用bt面板一键配置LNMP

centOS镜像下载

https://vault.centos.org/

环境准备

yum -y install wget  cmake gcc gcc-c++ ncurses  ncurses-devel  libaio-devel  openssl openssl-devel libtirpc-devel
yum install -y pcre pcre-devel

下载安装包与解压缩

进入指定目录

cd /usr/local/src/

下载安装包

wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.19.tar.gz
wget http://dl.bintray.com/boostorg/release/1.70.0/source/boost_1_70_0.tar.gz

解压缩装包

tar -xzvf mysql-8.0.19.tar.gz

创建mysql用户及组

[17:27:46 root@localhost ~]#groupadd mysql
[17:28:10 root@localhost ~]#useradd -g mysql mysql -s /bin/false
####创建用户mysql并加入到mysql组,不允许mysql用户直接登录系统
[17:28:11 root@localhost ~]#mkdir -p /data/mysql
####创建MySQL数据库存放目录
[17:29:13 root@localhost ~]#chown -R mysql:mysql /data/mysql
####设置MySQL数据库存放目录权限
[17:29:31 root@localhost ~]#mkdir -p /usr/local/mysql
####创建MySQL安装目录

boost文件拷贝到/usr/local/boost并解压

cd usr/local/src/boost_1_70_0
cp boost_1_70_0.tar.gz /usr/local/boost/
cd /usr/local/boost/
tar -xzvf boost_1_70_0.tar.gz

配置预编译

进入编译目录

cd /usr/local/src/mysql-8.0.19

进行预编译

cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DINSTALL_DATADIR=/data/mysql -DMYSQL_USER=mysql \
-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DFORCE_INSOURCE_BUILD=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DEXTRA_CHARSETS=all \
-DWITH_BOOST=/usr/local/boost

cmake -DBUILD_CONFIG=xtrabackup_release -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost && make -j4

编译检查

不编译检查的后果就是到后面出了bug,又要重新编译要等很长时间。

make test

编译

make -j 3 && make install

警告提示

不用理会即可

CMake Warning:
  Manually-specified variables were not used by the project:
    EXTRA_CHARSETS
    INSTALL_DATADIR
    MYSQL_USER
    WITH_EMBEDDED_SERVER

3.png.

初始化mysql数据库

修改目录权限

chown -R mysql:mysql /usr/local/mysql
chmod -R 755 /usr/local/mysql

修改配置文件

创建my.cnf文件

vi /usr/local/mysql/my.cnf

my.cnf内容

很多教程里面[mysql]里面都没有填

[client]
port=3306
socket=/tmp/mysql.sock
[mysqld]
port=3306
user = mysql
datadir = /usr/local/mysql/data
socket=/tmp/mysql.sock
tmpdir = /tmp
key_buffer_size=16M
max_allowed_packet=128M
default_authentication_plugin=mysql_native_password
open_files_limit = 60000
explicit_defaults_for_timestamp
server-id = 1
character-set-server = utf8
federated
max_connections = 1000
max_connect_errors = 100000
interactive_timeout = 86400
wait_timeout = 86400
sync_binlog=0
back_log=100
default-storage-engine = InnoDB
log_slave_updates = 1
[mysqldump]
quick
[client]
password="123456"
[mysqld-8.0]
sql_mode=TRADITIONAL
[mysqladmin]
force
[mysqld]
key_buffer_size=16M

初始化mysql

cd /usr/local/mysql/
./bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --character-set-server=utf8

执行效果

[root@localhost mysql]# cd /usr/local/mysql/
[root@localhost mysql]# ./bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --character-set-server=utf8
2021-02-22T10:52:11.467723Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.19) initializing of server in progress as process 9002
2021-02-22T10:52:11.484762Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2021-02-22T10:52:13.130071Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: hAqoGg=Rg8&;

如果报错

[root@localhost mysql]# ./bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --character-set-server=utf8
2021-02-23T01:13:35.403075Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.19) initializing of server in progress as process 10657
2021-02-23T01:13:35.404109Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2021-02-23T01:13:35.404650Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2021-02-23T01:13:35.404656Z 0 [ERROR] [MY-013236] [Server] The designated data directory /usr/local/mysql/data/ is unusable. You can remove all files that the server added to it.
2021-02-23T01:13:35.404754Z 0 [ERROR] [MY-010119] [Server] Aborting
2021-02-23T01:13:35.404885Z 0 [System] [MY-010910] [Server] /usr/local/mysql/bin/mysqld: Shutdown complete (mysqld 8.0.19)  Source distribution.
[root@localhost mysql]# ./bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --character-set-server=utf8
2021-02-23T01:13:44.614821Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.19) initializing of server in progress as process 10665
2021-02-23T01:13:44.615707Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2021-02-23T01:13:44.616220Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2021-02-23T01:13:44.616226Z 0 [ERROR] [MY-013236] [Server] The designated data directory /usr/local/mysql/data/ is unusable. You can remove all files that the server added to it.
2021-02-23T01:13:44.616308Z 0 [ERROR] [MY-010119] [Server] Aborting
2021-02-23T01:13:44.616442Z 0 [System] [MY-010910] [Server] /usr/local/mysql/bin/mysqld: Shutdown complete (mysqld 8.0.19)  Source distribution.
[root@localhost mysql]# vi /usr/local/mysql/my.cnf
[root@localhost mysql]# ./bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --character-set-server=utf8
2021-02-23T01:16:44.336656Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.19) initializing of server in progress as process 10764
2021-02-23T01:16:44.337511Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2021-02-23T01:16:44.338364Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2021-02-23T01:16:44.338370Z 0 [ERROR] [MY-013236] [Server] The designated data directory /usr/local/mysql/data/ is unusable. You can remove all files that the server added to it.
2021-02-23T01:16:44.338449Z 0 [ERROR] [MY-010119] [Server] Aborting
2021-02-23T01:16:44.338575Z 0 [System] [MY-010910] [Server] /usr/local/mysql/bin/mysqld: Shutdown complete (mysqld 8.0.19)  Source distribution.

删除安装目录下面data文件夹里面的数据,重新按照步骤操作,设置好my.cnf重新初始化

其他操作

添加到/etc目录的软链接

n -s /usr/local/mysql/my.cnf /etc/my.cnf

如果执行出错,请将/etc/my.cnf改成/etc/my_default.cnf或者删除也可以

把Mysql加入系统启动

cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld

增加执行权限

chmod 755 /etc/init.d/mysqld

加入开机启动

chkconfig mysqld on

编辑文件

vi /etc/rc.d/init.d/mysqld

mysqld文件按照情况修改下列内容

basedir=/usr/local/mysql#MySQL程序安装路径
datadir=/data/mysql#MySQl数据库存放目录

image-20210222190450739.png.

启动mysql服务

service mysqld start

image-20210223092904359.png.

常见问题

CMake Error at sql/cmake_install.cmake:50 (file):
  file RPATH_CHANGE could not write new RPATH:
    $ORIGIN/../lib/private
  to the file:
    /usr/local/software/mysql/bin/mysqld
  No valid ELF RPATH or RUNPATH entry exists in the file;
Call Stack (most recent call first):
  cmake_install.cmake:133 (include)
make: *** [Makefile:74:install] 错误 1

出现could not find rpcgen报错

CMake Error at plugin/group_replication/libmysqlgcs/cmake/rpcgen.cmake:104 (MESSAGE):
  Could not find rpcgen
Call Stack (most recent call first):
  plugin/group_replication/libmysqlgcs/CMakeLists.txt:53 (INCLUDE)
-- Configuring incomplete, errors occurred!
See also "/usr/local/src/mysql-8.0.21/CMakeFiles/CMakeOutput.log".
See also "/usr/local/src/mysql-8.0.21/CMakeFiles/CMakeError.log".

解决报错rpcgen的问题

问题:提示找不到rpcgen,yum源中也没有这个包,解决办法

wget https://github.com/thkukuk/rpcsvc-proto/releases/download/v1.4/rpcsvc-proto-1.4.tar.gz
tar xf rpcsvc-proto-1.4.tar.gz
cd  rpcsvc-proto-1.4
./configure && make && make install

make test时出现报错

The following tests FAILED:
      1 - hp_test1 (Not Run)
      2 - hp_test2 (Not Run)
      3 - pfs_instr_class (Not Run)
      4 - pfs_instr_class-oom (Not Run)
      5 - pfs_instr (Not Run)
      6 - pfs_instr-oom (Not Run)
      7 - pfs_account-oom (Not Run)
      8 - pfs_host-oom (Not Run)
      9 - pfs_user-oom (Not Run)
     10 - pfs_noop (Not Run)
     11 - pfs (Not Run)
     12 - pfs_misc (Not Run)
     13 - pfs_connect_attr (Not Run)
     14 - simple (Not Run)
     15 - skip (Not Run)
     16 - todo (Not Run)
     17 - skip_all (Not Run)
     18 - no_plan (Not Run)
     19 - basic (Not Run)
Errors while running CTest
make: *** [Makefile:130:test] 错误 8

但实际上是正常的,是可以编译的

CMAKE相关问题

CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
See also "/usr/local/src/mysql-8.0.19/CMakeFiles/CMakeOutput.log".

下载CMAKE

wget https://github.com/Kitware/CMake/releases/download/v3.14.3/cmake-3.14.3.tar.gz

解压

tar -zxvf cmake-3.14.3.tar.gz

编译安装

gmake
make install

centOS8.3出现问题

如果出现

CMake Error: Could not find CMAKE_ROOT !!!

清空缓存

hash -r

centOS8.2出现问题

如果出现

解决make: *** 没有指明目标并且找不到 makefile。

请在cmake-3.14.3输入以下口令

./configure --prefix=/usr/local/keepalived
make
make install

centOS7出现问题

centos7要用cmake3才能编译

Please install cmake3 (yum install cmake3)
CMake Error at CMakeLists.txt:84 (CMAKE_MINIMUM_REQUIRED):
  CMake 3.5.1 or higher is required.  You are running version 2.8.1

卸载cmake

yum remove cmake

gcc版本过低

GCC 5.3 or newer is required (-dumpversion says 4.8.5)

添加scl源

yum install centos-release-scl scl-utils-build

安装gcc

yum install devtoolset-8-gcc-c++ devtoolset-8-gcc
yum install scl-utils scl-utils-build
yum install devtoolset-7
scl enable devtoolset-7 bash

查看gcc版本

gcc -v

清空缓存

hash -r

查看gcc位置

which gcc

gcc位置显示

/opt/rh/devtoolset-7/root/usr/bin/gcc

编辑cmake文件

vim  cmake3/os/Linux.cmake

修改message后面的动态地址

编译

cmake3 . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DINSTALL_DATADIR=/data/mysql -DMYSQL_USER=mysql \
-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DFORCE_INSOURCE_BUILD=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DEXTRA_CHARSETS=all \
-DWITH_BOOST=/usr/local/src/boost_1_70_0 \
-DWITH_PARTITION_STORAGE_ENGINE=0

mysql5.6.51

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc  -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1  -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DMYSQL_TCP_PORT=3306  -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all  -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci

分区不足问题

+: fatal error: Killed signal terminated program cc1plus
compilation terminated.
make[2]: *** [sql/CMakeFiles/sql_gis.dir/build.make:154: sql/CMakeFiles/sql_gis.dir/gis/distance_functor.cc.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/Makefile2:11144: sql/CMakeFiles/sql_gis.dir/all] Error 2
make: *** [Makefile:163: all] Error 2
[root@localhost mysql]# dd if=/dev/zero of=/swapfile bs=1k count=2048000
记录了2048000+0 的读入
记录了2048000+0 的写出
2097152000 bytes (2.1 GB, 2.0 GiB) copied, 14.0854 s, 149 MB/s
[root@localhost mysql]# mkswap /swapfile
mkswap: /swapfile:不安全的权限 0644,建议使用 0600。
正在设置交换空间版本 1,大小 = 2 GiB (2097147904  个字节)
无标签,UUID=dbb783ff-8e37-4064-8a0d-7f671cdcaddc
[root@localhost mysql]# swapon /swapfile
swapon: /swapfile:不安全的权限 0644,建议使用 0600。
[root@localhost mysql]# swapon -s
文件名                类型        大小    已用    权限
/dev/dm-1                                  partition    2097148    5900    -2
/swapfile                                  file        2047996    0    -3
[root@localhost mysql]# echo "/var/swapfile swap swap defaults 0 0" >> /etc/fstab

重新执行

make -j 3 && make install

如果还不行我的是磁盘满了,还需要重新扩充磁盘

启动时提示

Starting MySQL.. ERROR! The server quit without updating PID file (/data/mysql/localhost.localdomain.pid).

centOS默认开启selinux,这里要关闭掉

打开/etc/selinux/config

vim /etc/selinux/config

把SELINUX=enforcing改为SELINUX=disable

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disable#enforcing
# SELINUXTYPE= can take one of these three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

然后保存重启

© 版权声明
THE END
喜欢就支持一下吧
点赞12
分享
评论 抢沙发

请登录后发表评论