0%

源码安装MySQL 8

下载源码

1
scp -r zyynanyou@10.166.13.45:mysql-boost-8.0.25.tar.gz ~/

当然wget也行

安装Wget
1
yum install wget

解压缩

1
tar -zxvf mysql-boost-8.0.25.tar.gz

image-20211025145043142

环境准备

1
mkdir -p ~/mysql-8.0.25/B19031707_build/package

因为上课是多人操作,所以自己建了个目录隔离

C环境

C/C++的环境要求5.8+

1
2
3
4
5
6
yum install centos-release-scl
yum install devtoolset-9-gcc*
scl enable devtoolset-9 bash

ln -s /opt/rh/devtoolset-9/root/bin/gcc /usr/bin/gcc
ln -s /opt/rh/devtoolset-9/root/bin/g++ /usr/bin/g++

CMake

安装此版本需要cmake版本3+

1
2
3
4
5
6
7
8
9
wget -c https://github.com/Kitware/CMake/releases/download/v3.22.0-rc1/cmake-3.22.0-rc1.tar.gz
tar -zxvf cmake-3.22.0-rc1.tar.gz
cd cmake-3.22.0-rc1
./configure
gmake
gmake install

ln -s /usr/local/bin/cmake /usr/bin/cmake
cmake --version

安装

先查看g++和gcc的路径

image-20211025151434594

源码目录下添加文件夹会有

CMake Error at CMakeLists.txt:382 (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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
cd ~/mysql-8.0.25/build
cmake .. \
-DCMAKE_INSTALL_PREFIX=$HOME/mysql-8.0.25/build/package \
-DWITH_EXTRA_CHARSETS:STRING=all \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=../boost \
-DWITH_EMBEDDED_SERVER:BOOL=OFF \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_SSL=system \
-DCMAKE_CXX_COMPILER=/usr/bin/g++ \
-DCMAKE_C_COMPILER=/usr/bin/gcc \
-DDEFAULT_CHARSET=utf8mb4 \
-DWITH_DEBUG=1
## 上边开启了debug
## 注意gcc路径
cd ~/mysql-8.0.25/build
rm -rf *
mkdir package
cmake .. \
-DCMAKE_INSTALL_PREFIX=$HOME/mysql-8.0.25/build/package \
-DWITH_EXTRA_CHARSETS:STRING=all \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=../boost \
-DWITH_EMBEDDED_SERVER:BOOL=OFF \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_SSL=system \
-DCMAKE_CXX_COMPILER=/usr/local/gcc/bin/g++ \
-DCMAKE_C_COMPILER=/usr/local/gcc/bin/gcc \
-DDEFAULT_CHARSET=utf8mb4 \
-DWITH_DEBUG=1

问题1

CMake Error at cmake/readline.cmake:71 (MESSAGE):
Curses library not found. Please install appropriate package,

remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
cmake/readline.cmake:105 (FIND_CURSES)
cmake/readline.cmake:199 (MYSQL_USE_BUNDLED_EDITLINE)
CMakeLists.txt:1422 (MYSQL_CHECK_EDITLINE)

1
2
yum install ncurses-libs
yum install ncurses-devel

编译

1
2
make -j 8
make install

image-20211025165556879

遇到的问题:make -j 8内存爆了,调小一些就行

image-20211025175322628

迁移到新用户

1
2
3
4
5
6
7
8
useradd B19031707
cd package
mkdir /home/B19031707/mysql
cp -r bin lib share /home/B19031707/mysql/
chown -R B19031707 /home/B19031707/mysql/
su B19031707
cd ~
# 剩下的步骤在此用户中执行

修改配置文件

1
vim /my.cnf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[mysqld]
port=33306
bind_address=10.22.224.73
socket=/home/B19031707/mysql/bin/mysql.sock
server-id=11
max_connections = 10000
datadir=/home/B19031707/mysql/data/data
pid-file=/home/B19031707/mysql/bin/mysqld.pid
innodb_data_home_dir=/home/B19031707/mysql/data/data
innodb_log_group_home_dir=/home/B19031707/mysql/data/redo
innodb_undo_directory=/home/B19031707/mysql/data/undo
tmpdir=/home/B19031707/mysql/data/tmp
log-error=/home/B19031707/mysql/log/mysqld.log
innodb_data_file_path = ibdata1:500M:autoextend
innodb-file-per-table
innodb_buffer_pool_size = 32G
innodb_buffer_pool_instances = 8
log-bin=../binlog/mysql-bin
default-time-zone='+08:00'
[client]
port=33306
socket=/home/B19031707/mysql/bin/mysql.sock

启动

  • 安装

    1
    2
    3
    cd /home/B19031707/mysql
    mkdir -p data/data data/redo data/tmp data/binlog data/relaylog data/undo
    mkdir log
  • 初始化

    1
    ./bin/mysqld --defaults-file="$HOME/my.cnf" --datadir="$HOME/mysql/data/data" --initialize-insecure
  • 启动

    1
    ./bin/mysqld --defaults-file="$HOME/my.cnf" --datadir="$HOME/mysql/data/data" --pid-file="$HOME/mysql/bin/mysqld.pid"

    image-20211025194656661

连接

1
mysql -u root -h localhost -P 33306 -p

出现错误

ERROR 2003 (HY000): Can’t connect to MySQL server on ‘10.22.224.73:33360’ (111)

需要创建一个套接字文件在tmp

干脆创建个软连接骗一下,还真行

ln -s /home/B19031707/mysql/bin/mysql.sock /tmp/mysql.sock

修改用户名和密码

1
2
3
4
5
alter user 'root'@'localhost' identified by '-p0-p0-p0';
CREATE USER 'root'@'%' IDENTIFIED BY '-p0-p0-p0';
grant all on *.* to 'root'@'%';
flush privileges;
exit

问题反馈

image-20211025200457795

p后最好不明文输入密码,如输入密码,p和密码之间不能用空格。

1
2
3
ssh -gNfL 14085:192.188.1.70:22238 root@10.22.244.49
ssh -gNfL 14080:172.30.1.240:80 root@10.22.244.49
ssh -gNfL 14090:10.22.224.60:5022 root@10.22.244.49

mysql -u root -P 4090

-----------看到底线啦 感谢您的阅读-------------