1  下载

    1.1 下载网址: www.mysql.com

    1.2 下载方法

          1.2.1 进入主页后,选择 DOWNLOADS ,这时我们进入了下载页面。如下载的网址所示https://www.mysql.com/downloads/

          1.2.2 进入下载页面后,可以看到很多产品,这里我们将滚动条拉到最下面。 我们要下载的是MySQL Community Edition(GPL)

          1.2.3 进入MySQL Community后。 selecting operating system选择Source Code;version根据大家的需求,这里我们选择Generic Linux

          1.2.4 这里我们看到有两个resource,供我们下载。这里推荐下载Includes Boost Headers

                   Note: boost 是C++开发库的扩展库,目的是为了将C++库标准化,实现跨平台。这里我们主要用其编译MySQL code。


2  编译

    2.1 解压

          tar -zxvf mysql-boost-5.7.18.tar.gz

    2.2 编译

          2.2.1 创建编译工程

              cd mysql-5.7.18-src

              mkdir bld

              cmake .. -DDOWNLOAD_BOOST=0 -DWITH_BOOST=../boost/ -DMYSQL_DATADIR=/mysqldb/mysql-5.7.18/data

              note1: cmake -(cross platform make)是一个跨平台的编译工具,主要用来生成makefile或project文件。只是 CMake 的组态档取名为 CMakeLists.txt。

              note2: cmake 在编译mysql有很多option,可以通过MySQL的官方查看。

          2.2.2 编译

              make


3  安装

    3.1 make install

    note: 由于我们在cmake生成project时,没有指定mysql的安装目录,安装完成后,大家可以查看mysql的安装目录。

    note: 如果需要指定安装目录,请在cmake中使用option: -DCMAKE_INSTALL_PREFIX=/mysqldb/bin

4  初始化

    cd /mysqldb/mysql-5.7.18

    chown -R mysql .
    chgrp -R mysql .
    bin/mysql_install_db --user=mysql    # Before MySQL 5.7.6
    bin/mysqld --initialize --user=mysql # MySQL 5.7.6 and up

    log:

        /mysqldb/mysql-5.7.18/bin/mysqld --initialize --datadir=/mysqldb/mysql-5.7.18/data --socket=/mysqldb/mysql-5.7.18/mysql.sock --port=3308
        2017-06-12T13:38:26.685880Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
        2017-06-12T13:38:26.685938Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
        2017-06-12T13:38:26.686148Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
        2017-06-12T13:38:26.834957Z 0 [Warning] InnoDB: New log files created, LSN=45790
        2017-06-12T13:38:26.860155Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
        2017-06-12T13:38:26.913633Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server         has been started. Generating a new UUID: 69df5d80-4f74-11e7-b356-000c29b43c62.
        2017-06-12T13:38:26.914116Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
        2017-06-12T13:38:26.914709Z 1 [Note] A temporary password is generated for root@localhost: x58xx7Smry,P

    note: 初始化完成后,mysql会为root@localhost 创建一个初始化的密码。


5  启动

    bin/mysqld_safe --user=mysql --socket=/mysqldb/mysql-5.7.18/mysql.sock --port=3308 &


6  登录

    /mysqldb/mysql-5.7.18/bin/mysql  --socket=/mysqldb/mysql-5.7.18/mysql.sock --port=3308 -p