一般下载有两种方式,一种是直接apt命令下载,另外就是 指定目录下载。类似于windows下面安装程时,一键安装和自定义安装。这里记录的是指定目录下载。
    安装依赖apt install build-essential cmake bison libncurses5-dev libssl-dev pkg-config -y
    apt install make cmake gcc g++ perl bison libaio-dev libncurses5 libncurses5-dev libnuma-dev -y

    开始记录。首先打开官网下载页面:https://dev.mysql.com/downloads/mysql/,选择MySQL版本。

    下载源码
    源码包分为带boost版和不带boost版的,方便起见直接下载带boost的。
    wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-boost-8.0.28.tar.gz
    tar xzv -f mysql-boost-8.0.28.tar.gz
    cd mysql-8.0.28/

    编译安装
    cmake的完整选项列表参考https://dev.mysql.com/doc/refman/8.0/en/source-configuration-options.html

    1. cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DWITH_BOOST=boost -DFORCE_INSOURCE_BUILD=ON
    2. make && make install

    初始配置

    详细参考https://dev.mysql.com/doc/refman/8.0/en/installing-source-distribution.html

    添加mysql用户组和配置文件权属。

    groupadd mysql
    useradd -g mysql mysql
    mkdir -p /usr/local/mysql/data
    chown -R mysql:mysql /usr/local/mysql
    初始化安装。

    /usr/local/mysql/bin/mysqld —initialize —user=mysql —basedir=/usr/local/mysql —datadir=/usr/local/mysql/data
    这一步会打印输出随机生成的root账号初始密码,找个小本本记下来待会要用这个密码连接登录的。[Server] A temporary password is generated for root@localhost: !YAH0uS%AS>q。

    生成ssl(可选)。

    /usr/local/mysql/bin/mysql_ssl_rsa_setup —user=mysql —basedir=/usr/local/mysql —datadir=/usr/local/mysql/data
    新建一个全局用的简单的配置文件。

    vim /etc/my.cnf
    # 然后写入以下内容 #
    [client]
    socket = /tmp/mysql.sock

    [mysqld]
    socket = /tmp/mysql.sock
    basedir = /usr/local/mysql
    datadir = /usr/local/mysql/data
    ⑤开启服务

    详细参考https://dev.mysql.com/doc/refman/8.0/en/postinstallation.html

    配置mysqld服务。

    cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
    chmod +x /etc/init.d/mysqld
    update-rc.d mysqld defaults
    service mysqld start
    添加PATH。

    echo -e ‘# MySQL PATH\nexport PATH=/usr/local/mysql/bin:$PATH\n’ >> /etc/profile
    source /etc/profile
    连接登录MySQL并修改root账户密码(需要使用第④步生成的密码)。

    mysql -uroot -p’!YAH0uS%AS>q’
    mysql> ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘1024’;
    因为本次安装只是个人使用(非生产环境),所以可以额外的将账户密码信息写入配置文件,以后连接就不用再输入了(懒人专用)。然后进入MySQL修改开启root账户可远程连接。

    vim /etc/my.cnf
    [client]
    # 把这几行添加到client选项组下面 #
    user = root
    password = 1024
    port = 3306
    root@zoo:/home/zoo/mysql-8.0.16# mysql
    Welcome to the MySQL monitor. Commands end with ; or \g.
    Your MySQL connection id is 11
    Server version: 8.0.16 Source distribution

    Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

    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> UPDATE mysql.user SET Host = ‘%’ WHERE User = ‘root’;
    Query OK, 1 row affected (0.01 sec)
    Rows matched: 1 Changed: 1 Warnings: 0

    mysql> FLUSH PRIVILEGES;
    Query OK, 0 rows affected (0.01 sec)

    mysql>

    遇到的问题。

    ①在源码包目录下编译错误

    CMake Error at CMakeLists.txt:301 (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
    根据输出信息,安装非常不建议在源码包下面直接编译。如果在其他目录下,对于同一份源码,你可以执行和生成多份cmake builds。并且可以简易地cleanup,即删除build目录即可。这个错误在MySQL5.7和MariaDB的源码编译过程中并不会碰到,应该是新的8.0版本的改进之一了。其用意感觉应该是为了方便系统管理员在一份源码下灵活地安装多份配置各异的MySQL实例。但在本地自己安装用的时候,并不需要考虑这么多,cmake时按照提示添加“ -DFORCE_INSOURCE_BUILD=1 ”选项即可。

    ②缺失openssl系统依赖

    Cannot find appropriate system libraries for WITH_SSL=system.
    Make sure you have specified a supported SSL version.
    Valid options are :
    system (use the OS openssl library),
    yes (synonym for system),
    ,
    wolfssl (use wolfSSL. See extra/README-wolfssl.txt on how to set this up)

    CMake Error at cmake/ssl.cmake:68 (MESSAGE):
    Please install the appropriate openssl developer package.
    手动安装一下即可“ apt install libssl-dev ”。

    ③缺失pkg-config依赖。

    CMake Warning at cmake/pkg-config.cmake:29 (MESSAGE):
    Cannot find pkg-config. You need to install the required package:

    Debian/Ubuntu: apt install pkg-config
    RedHat/Fedora/Oracle Linux: yum install pkg-config
    SuSE: zypper install pkg-config

    Call Stack (most recent call first):
    cmake/rpc.cmake:29 (MYSQL_CHECK_PKGCONFIG)
    plugin/group_replication/libmysqlgcs/configure.cmake:57 (MYSQL_CHECK_RPC)
    plugin/group_replication/libmysqlgcs/CMakeLists.txt:28 (INCLUDE)


    CMake Error at /usr/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
    Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
    Call Stack (most recent call first):
    /usr/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
    /usr/share/cmake-3.10/Modules/FindPkgConfig.cmake:36 (find_package_handle_standard_args)
    cmake/pkg-config.cmake:36 (FIND_PACKAGE)
    cmake/rpc.cmake:29 (MYSQL_CHECK_PKGCONFIG)
    plugin/group_replication/libmysqlgcs/configure.cmake:57 (MYSQL_CHECK_RPC)
    plugin/group_replication/libmysqlgcs/CMakeLists.txt:28 (INCLUDE)
    按照打印输出的提示手动安装一下即可“ apt install pkg-config ”。