Source Installation for Mysql8.0

Keywords: Database MySQL cmake ftp yum

The 8.0 version of Mysql has been around for some time. Under recent research, the first step is to install and deploy it. Here is the source installation process.

1. Environmental Preparation

OS: CentOS 7.4
DB: Mysql 8.0.18
Hardware: 40G or more space, 4G or more memory

2. Environmental Preparation

1. Download Files

Download mysql-boost-8.0.18.tar.gz

2. Install dependent packages

# yum -y install gcc gcc-c++ ncurses-devel openssl-devel cmake3 bison wget bzip2
# ln -s /usr/bin/cmake3 /usr/bin/cmake

3. User Group Settings

useradd mysql
groupadd mysql
mkdir -p /usr/local/mysql
mkdir -p /data/mysql8.0/log
chown -R mysql:mysql /data/mysql8.0/
chown -R mysql:mysql /usr/local/mysql

4. System Parameter Settings

echo -e "
kernel.sem = 250 32000 100128
kernel.sysrq = 0
net.core.rmem_max = 33554432
net.core.wmem_max = 33554432
net.core.rmem_default = 262144
net.core.wmem_default = 262144
net.core.somaxconn = 8192
net.core.netdev_max_backlog = 16384
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.all.secure_redirects = 0
net.ipv4.conf.default.secure_redirects = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.tcp_rmem = 409665536 16777216
net.ipv4.tcp_wmem = 409632768 16777216
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_max_syn_backlog = 8192
net.nf_conntrack_max = 1048576
net.netfilter.nf_conntrack_tcp_timeout_established = 12000
vm.swappiness = 0
vm.zone_reclaim_mode = 0" >> /etc/sysctl.conf

sysctl –p

for i in $(ls -d /sys/block/[svh]d[a-z])
do
fqueue=$i/queue/scheduler
echo deadline > $fqueue
done

sed -i '/kernel/ s/$/ elevator=deadline numa=off/g' /etc/grub.conf

limit="\n*\tsoft\tnofile\t65536\n*\thard\tnofile\t65536\n*\tsoft\tnproc\t131072\n*\thard\tnproc\t131072\n*\tsoft\tstack\tunlimited\n*\thard\tstack\tunlimited"
echo -e "$limit" >> /etc/security/limits.conf
echo -e "$limit" >> /etc/security/limits.d/20-nproc.conf

5. Compile and Install

cd mysql-8.0.18/
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql  -DCMAKE_CXX_COMPILER=/usr/bin/g++ -DMYSQL_DATADIR=/data/mysql8.0/datanode1 -DMYSQL_UNIX_ADDR=/data/mysql8.0/mysql.sock -DWITH_BOOST=/usr/local/boost -DSYSCONFDIR=/usr/local/mysql -DFORCE_INSOURCE_BUILD=1 -DWITH_SSL=system -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_EXTRA_CHARSETS=all -DFORCE_INSOURCE_BUILD=1 -DCOMPILATION_COMMENT="Kenyon's MySQL 8.0"
make && make install

--PS: Can download ahead of time boost_1_70_0.tar.gz Place in/usr/local/boost Below,Or use-DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost download

6. Configuration parameters

[client]
port = 3306
socket = /data/mysql8.0/datanode1/mysql.sock
default-character-set = utf8mb4

[mysqld]
server-id = 99999			## With appropriate adjustments, you can select an ipv4 address
port = 3306
user = mysql
basedir = /usr/local/mysql
datadir =/data/mysql8.0/datanode1
tmpdir = /tmp
socket = /data/mysql8.0/datanode1/mysql.sock
pid-file = /data/mysql8.0/datanode1/mysql.pid
default-storage-engine = INNODB
lower_case_table_names = 1
transaction_isolation = READ-COMMITTED
secure_file_priv =

# connection
back_log = 400
max_connections = 2000
interactive_timeout = 28800
wait_timeout = 28800
slave_net_timeout = 300
skip_name_resolve = on

# binlog
log-bin = mysql-bin
log-bin-index = mysql-bin
relay-log = relay-bin
relay-log-index = relay-bin
expire_logs_days = 7
binlog_cache_size = 8M
binlog_format = ROW
log_slave_updates = 1
relay_log_purge = 1
log-bin-trust-function-creators = 1
#slave_parallel_workers = 4

# caches & limits
bulk_insert_buffer_size = 8M
innodb_buffer_pool_size = 18G    ## Adjust appropriately: 60% memory
innodb_log_buffer_size = 32M
innodb_sort_buffer_size = 4M
join_buffer_size = 4M
sort_buffer_size = 4M
key_buffer_size = 16M
innodb_max_dirty_pages_pct = 15
max_allowed_packet = 16M
max_heap_table_size = 16M
query_cache_size = 0
query_cache_limit = 8M
query_cache_type = off
read_buffer_size = 512K
read_rnd_buffer_size = 512K
open-files-limit = 10240
table_definition_cache = 4096
table_open_cache = 4096
table_open_cache_instances = 16

# thread
thread_cache_size = 300
innodb_thread_concurrency = 0
innodb_io_capacity = 500
innodb_io_capacity_max = 1000

# innodb log
innodb_flush_method = O_DIRECT
innodb_log_file_size = 1G
innodb_autoextend_increment = 128
innodb_flush_log_at_trx_commit = 2
innodb_log_files_in_group = 3
innodb_log_group_home_dir = /data/mysql8.0/datanode1/
innodb_print_all_deadlocks
sync_binlog = 1000

# innodb file
innodb_data_home_dir = /data/mysql8.0/datanode1/
innodb_data_file_path = ibdata:2G:autoextend
innodb_file_per_table = 1
innodb_file_format = Barracuda
innodb_file_format_max = Barracuda
innodb_large_prefix = 1
tmp_table_size = 4M

# data
innodb_autoinc_lock_mode = 1
auto_increment_increment = 3        ## Adjust appropriately
auto_increment_offset = 1           ## Adjust appropriately
max_prepared_stmt_count = 65530

# character
character-set-server = utf8mb4
character-set-client = utf8mb4

# logging
slow-query-log = 1
slow-query-log-file = /data/mysql8.0/log/mysql-slow.log
log-error = /data/mysql8.0/log/mysql-error.log
long_query_time	= 1

# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

7. Initialization

/usr/local/mysql/bin/mysqld --initialize --basedir=/usr/local/mysql --datadir=/data/mysql8.0/datanode1  --lower-case-table-names=1 --user=mysql

8. Set up self-start

# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
# chkconfig --add mysqld
# chkconfig mysqld on

9. Startup and shutdown

service mysqld start | stop

mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.18    |
+-----------+
1 row in set (0.00 sec)

3. Set of Issues

1. The cmake version is too low

yum Incoming cmake Version 2.x Edition, mysql8 Source installation requirements are 3.5.1 In the above version, the following errors will be reported:

[root@gp07 mysql-8.0.18]#  cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql8.0/data -DMYSQL_UNIX_ADDR=/data/mysql8.0/mysql.sock -DWITH_BOOST=/root/mysql-8.0.0-dmr/boost -DSYSCONFDIR=/usr/local/mysql -DWITH_SSL=system -DMYSQL_TCP_PORT=3306  -DENABLED_LOCAL_INFILE=1 -DENABLE_DTRACE=0 -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_EMBEDDED_SERVER=1 -DCOMPILATION_COMMENT="Kenyon's MySQL 8.0"
-- Running cmake version 2.8.12.2
CMake Warning at CMakeLists.txt:43 (MESSAGE):
  Please use cmake3 rather than cmake on this platform


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


-- Configuring incomplete, errors occurred!


--The solution is to remove the old cmake Version, with new cmake3 Version Replacement cmake2 Edition
rm -f /usr/bin/cmake2
rm -f /usr/bin/cmake

yum install cmake3
ln -s /usr/bin/cmake3 /usr/bin/cmake

2. Force Source Installation

-- Running cmake version 3.14.6
-- MySQL 8.0.18
-- Source directory /root/software/mysql-8.0.18
-- Binary directory /root/software/mysql-8.0.18
CMake Error at CMakeLists.txt:341 (MESSAGE):
  Please do not build in-source.  Out-of source builds are highly
  recommended: you can have multiple builds for the same source, and there is
  an easy way to do cleanup, simply remove the build directory (note that
  'make clean' or 'make distclean' does *not* work)

  You *can* force in-source build by invoking cmake with
  -DFORCE_INSOURCE_BUILD=1

//As prompted, add the -DFORCE_INSOURCE_BUILD=1 parameter when cmake compiles

3. The gcc version is too low

gcc requires version 5.3 or higher, actual version 4.8.5

-- Source directory /root/software/mysql-8.0.18
-- Binary directory /root/software/mysql-8.0.18
CMake Warning at CMakeLists.txt:339 (MESSAGE):
  This is an in-source build


-- CMAKE_GENERATOR: Unix Makefiles
CMake Error at cmake/os/Linux.cmake:59 (MESSAGE):
  GCC 5.3 or newer is required (-dumpversion says 4.8.5)
Call Stack (most recent call first):
  CMakeLists.txt:442 (INCLUDE)

The solution is to upgrade gcc, which is a very long process

--Direct Installation gcc May=Errors will occur and installation is required gmp,mpfr,mpc,Each component has a back-and-forth relationship and is executed in this order
configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.
Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify

wget ftp://ftp.gnu.org/gnu/mpc/mpc-1.1.0.tar.gz     -P /usr/local/src
wget ftp://ftp.gnu.org/gnu/gmp/gmp-6.1.2.tar.bz2    -P /usr/local/src
wget http://ftp.gnu.org/gnu/mpfr/mpfr-4.0.2.tar.gz  -P /usr/local/src
wget http://ftp.gnu.org/gnu/m4/m4-1.4.18.tar.gz     -P /usr/local/src
wget http://ftp.gnu.org/gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.gz -P /usr/local/src

tar -zxvf mpc-1.1.0.tar.gz
tar -zxvf mpfr-4.0.2.tar.gz
tar -jxvf gmp-6.1.2.tar.bz2
tar -zxvf m4-1.4.18.tar.gz
tar -zxvf gcc-9.2.0.tar.gz

--decompression gmp Need yum install bzip2 -y

mkdir -p /usr/local/m4-1.4.18
mkdir -p /usr/local/gmp-6.1.2
mkdir -p /usr/local/mpfr-4.0.2
mkdir -p /usr/local/mpc-1.1.0
mkdir -p /usr/local/gcc-9.2.0

cd m4-1.4.18
./configure --prefix=/usr/local/m4-1.4.18
make && make install
ln -s /usr/local/m4-1.4.18/bin/m4 /usr/bin/m4

cd  gmp-6.1.2
./configure --prefix=/usr/local/gmp-6.1.2 
make && make install

cd mpfr-4.0.2
./configure --prefix=/usr/local/mpfr-4.0.2/ --with-gmp=/usr/local/gmp-6.1.2/
make && make install

cd mpc-1.1.0
./configure --prefix=/usr/local/mpc-1.1.0 --with-gmp=/usr/local/gmp-6.1.2/ --with-mpfr=/usr/local/mpfr-4.0.2/
make && make install

[root@kenyon ]# more /etc/ld.so.conf
include ld.so.conf.d/*.conf

/usr/local/gmp-6.1.2/lib
/usr/local/mpfr-4.0.2/lib
/usr/local/mpc-1.1.0/lib

# ldconfig

cd gcc-9.2.0
./configure --prefix=/usr/local/gcc-9.2.0 --with-gmp=/usr/local/gmp-6.1.2  --with-mpfr=/usr/local/mpfr-4.0.2 --with-mpc=/usr/local/mpc-1.1.0 --disable-multilib 
make && make install
--Compiled for a long time....3 About an hour....

mv /usr/bin/gcc /usr/bin/gcc4.8.5
mv /usr/bin/g++ /usr/bin/g++4.8.5

ln -s /usr/local/gcc-9.2.0/bin/gcc /usr/bin/gcc
ln -s /usr/local/gcc-9.2.0/bin/g++ /usr/bin/g++

4. Compile Parameters

c++: error: unrecognized command line option '-std=c++14'

The solution is to add -DCMAKE_CXX_COMPILER=/usr/bin/g++ at compile time

5. Dynamic Library Problems

../runtime_output_directory/uca9dump: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by ../runtime_output_directory/uca9dump)

The reason is that the gcc has been upgraded without replacing the old version of the gcc dynamic library with the upgraded gcc dynamic library
Solution:
cp /usr/local/src/gcc-9.2.0/x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6.0.27 /usr/lib64
cd /usr/lib64
ln -s libstdc++.so.6.0.27 libstdc++.so.6

6. Source syscall problem

In the function'void buf_pool_create'(buf_pool_t*, ulint, ulint, std:: mutex*, dberr_t&): /root/mysql-8.0.17/storage/innobase/buf/buf0buf.cc:1220:44: Error:'SYS_gettid' has not declared setpriority (PRIO_PROCESS, (pid_t) SYL (SYS_scalgettid), -20) in this scope;

Solution: Add at the beginning of the source file storage/innobase/buf/buf0buf.cc: #include "sys/syscall.h"

7. swap_lint problem

a.
/root/mysql-8.0.18/storage/innobase/lock/lock0lock.cc:1359:9: error: 'os_compare_and_swap_thread_id' was not declared in this scope; did you mean 'os_compare_and_swap_uint64'

//Solution: Replace os_compare_and_swap_thread_id in source file lock0lock.cc with os_compare_and_swap_lint

b.
/root/mysql-8.0.18/storage/innobase/trx/trx0trx.cc: In function 'void trx_init(trx_t*)':
/root/mysql-8.0.18/storage/innobase/trx/trx0trx.cc:222:5: error: 'os_compare_and_swap_thread_id' was not declared in this scope; did you mean 'os_compare_and_swap_lint'?
  222 |     os_compare_and_swap_thread_id(&trx->killed_by, thread_id, 0);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |     os_compare_and_swap_lint
/root/mysql-8.0.18/storage/innobase/trx/trx0trx.cc: In function 'void trx_kill_blocking(trx_t*)':
/root/mysql-8.0.18/storage/innobase/trx/trx0trx.cc:3230:5: error: 'os_compare_and_swap_thread_id' was not declared in this scope; did you mean 'os_compare_and_swap_lint'?
 3230 |     os_compare_and_swap_thread_id(&victim_trx->killed_by, thread_id, 0);

//Solution:
//Modify the storage/innobase/trx/trx0trx.cc to replace os_compare_and_swap_thread_id with os_compare_and_swap_lint, noting that there are two modifications

8. Initialization failure

2019-12-02T11:31:16.760733+08:00 0 [System] [MY-010116] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.18) starting as process 10686
2019-12-02T11:31:16.776210+08:00 1 [ERROR] [MY-011011] [Server] Failed to find valid data directory.
2019-12-02T11:31:16.776500+08:00 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2019-12-02T11:31:16.776570+08:00 0 [ERROR] [MY-010119] [Server] Aborting
2019-12-02T11:31:16.777890+08:00 0 [System] [MY-010910] [Server] /usr/local/mysql/bin/mysqld: Shutdown complete (mysqld 8.0.18)  Kenyon's MySQL 8.0.18

Solution:
Once you've dealt with the above issues, re-make, make, and make install

4. Summary

1. mysql8 source installation is more demanding than previous versions 7, especially compilers, which take longer to compile
2. Previously lower versions (pre-5.7) were able to customize various engine and initialization parameters. The new version was installed by default and no longer required to compile such parameters.
3. The official does not recommend source code compilation at present. In terms of time cost, it is recommended to choose RPM installation or to package rpm to install itself after compilation is completed.
4. A pit found so far is that to set case sensitivity, you need to specify it when initializing the database (initialize --lower-case-table-names=1), otherwise you can only export it for reinitialization.
5. The password will be printed at the end of the screen log after the initialization is completed. You must change the password before you can use it for the first login.

5. Reference:

https://www.twblogs.net/a/5d7351bebd9eee5327ff7d28/zh-cn
http://www.zhongweicheng.com/?p=2503
https://www.mysql.com

Posted by ahmedkl on Thu, 19 Dec 2019 17:59:18 -0800