首先在编译之前,我们要了解相关mysql 5.7的编译选项,官网编译选项地址:http://dev.mysql.com/doc/refman/5.7/en/source-configuration-options.html
 
1、安装编译工具cmake和其他的c语言编译环境
 
 yum install -y make gcc gcc-c++ ncurses-devel cmake
 
编译选项解释
cmake指定编译选项的方式不同于make,其实现方式对比如下:
 
./configure --help
make                 |cmake
---------------------|--------------------------
./configure          |cmake .
./configure --help   |cmake . -LH or ccmake .
 
 
2、编译安装
(1)从MySQL 5.7.5开始Boost库是必需的,直接cmake指定选项,下面是自动下载,如果太慢可以手动下载,放在<directory> 里面,就OK。
-DDOWNLOAD_BOOST=0
-DWITH_BOOST=<directory>
 
 
(2)系统会自动下载 boost库,也可以手动。下面编译的时候我加了这个选项,自动下载。
-DDOWNLOAD_BOOST=1
-DWITH_BOOST=<directory>
 
 
对于mysql boost 库不能低于1.59.0,centos 7默认1.53.0
ERROR:MySQL currently requires boost_1_59_0  #更新到1.59版本就好
 
编译过程1个小时左右,视cpu性能而定。指定红色部分的目录的时候,目录必须要存在,不然编译后找不到相关文件。编译的时候建议在mysql用户下编译
mkdir /usr/local/mysql
mkdir /data/mysql                                          #在自定义分区data下创建mysql目录
groupadd mysql
useradd mysql -g mysql                                    #创建用户mysql属于用户组mysql
passwd mysql                                           #设置mysql用户的密码,以后可以登录这个用户方便mysql维护。
 
yum install openssl openssl-devel bison*
 
 
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql \
-DSYSCONFDIR=/usr/local/mysql/ \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DWITH_LIBWRAP=0 \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/var/lib
make
make install
chown -R mysql.mysql /usr/local/mysql /data/mysql          #把这个目录权限给用户mysql,编译之后再执行
 
编译后你会发现在mysql的根目录没有my.cnf配置文件,这时候系统会用自带/etc/my.cnf作为你的配置文件,这和你编译的配置文件路径不一样。建议把/etc/my.cnf改名为my.cng.back,然后用cp support-files/my-default.cnf ../my.cnf   将默认配置文件复制在你编译配置文件的路径。但是需要自己更改默认设置的配置文件。
 
my.cnf配置
[client]
#password = [your_password]
#socket = /usr/local/mysql/mysql.sock
default-character-set= utf8
 
[mysqld]
port = 3306
socket = /usr/local/mysql/mysql.sock
back_log = 120
max_connections = 3000
max_connect_errors = 30
max_allowed_packet = 32M
binlog_cache_size = 4M
max_heap_table_size = 128M
sort_buffer_size = 16M
join_buffer_size = 16M
query_cache_size = 128M
query_cache_limit = 4M
ft_min_word_len = 8
transaction_isolation = REPEATABLE-READ
key_buffer_size = 128M
read_buffer_size = 8M
skip_name_resolve = 1
basedir = /usr/local/mysql
datadir = /data/mysql
tmpdir = /tmp
log_error = error.log
default-storage-engine = INNODB
character-set-server = utf8
collation-server = utf8_general_ci
server-id = 1
 
[mysql]
no-auto-rehash
 
 
 
3、初始化数据库,并更改root用户密码
./bin/mysqld --initialize --datadir=/data/mysql --user=mysql          #初始化数据库的时候,最后一行输出会有一个root用户的随机密码,记住这个随机密码,第一次用root用户登录是要这个随机密码的。在进行其他命令操作之前要修改root用户的密码,命令如下:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpassword');
 
4、开启mysql服务,我这里是用mysql用户启动。
 
/usr/local/mysql/support-files/mysql.server start
 
 
附录:
 
[root@cloud mysql-5.7.15]# cmake . -LH
-- Running cmake version 2.8.11
-- Could NOT find Git (missing:  GIT_EXECUTABLE)
-- Configuring with MAX_INDEXES = 64U
-- SIZEOF_VOIDP 8
-- MySQL 5.7.15
-- Packaging as: mysql-5.7.15-Linux-x86_64
-- Local boost dir /var/lib/boost_1_59_0
-- Local boost zip /var/lib/boost_1_59_0.tar.gz
-- Found /var/lib/boost_1_59_0/boost/version.hpp
-- BOOST_VERSION_NUMBER is #define BOOST_VERSION 105900
-- BOOST_INCLUDE_DIR /var/lib/boost_1_59_0
-- OPENSSL_INCLUDE_DIR = /usr/include
-- OPENSSL_LIBRARY = /usr/lib64/libssl.so
-- CRYPTO_LIBRARY = /usr/lib64/libcrypto.so
-- OPENSSL_MAJOR_VERSION = 1
-- SSL_LIBRARIES = /usr/lib64/libssl.so;/usr/lib64/libcrypto.so;dl
-- WITH_PROTOBUF=bundled
-- protobuf version is 2.6
-- Using cmake version 2.8.11
-- Disabling -Wunused-but-set-variable warning for building NDB
-- Disabling -Wstrict-aliasing warning for building NDB
-- Not building NDB
-- Using Boost headers from /var/lib/boost_1_59_0
-- MYSQLX - Text log of protobuf messages enabled
-- Library mysqlclient depends on OSLIBS -lpthread;/usr/lib64/libz.so;m;rt;/usr/lib64/libssl.so;/usr/lib64/libcrypto.so;dl
-- Library mysqlserver depends on OSLIBS -lpthread;/usr/lib64/libz.so;m;rt;/usr/lib64/libssl.so;/usr/lib64/libcrypto.so;dl;crypt
-- INSTALL mysqlclient.pc lib/pkgconfig
-- Skipping deb packaging on unsupported platform .
-- CMAKE_BUILD_TYPE: RelWithDebInfo
-- COMPILE_DEFINITIONS: _GNU_SOURCE;_FILE_OFFSET_BITS=64;HAVE_CONFIG_H;HAVE_LIBEVENT1
-- CMAKE_C_FLAGS:  -Wall -Wextra -Wformat-security -Wvla -Wwrite-strings -Wdeclaration-after-statement
-- CMAKE_CXX_FLAGS:  -Wall -Wextra -Wformat-security -Wvla -Woverloaded-virtual -Wno-unused-parameter
-- CMAKE_C_FLAGS_RELWITHDEBINFO: -O3 -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF
-- CMAKE_CXX_FLAGS_RELWITHDEBINFO: -O3 -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF
-- Configuring done
-- Generating done
-- Build files have been written to: /usr/src/mysql-5.7.15
-- Cache values
// Path to a file.
BOOST_INCLUDE_DIR:PATH=/var/lib/boost_1_59_0
 
// Bundle mecab and ipadic with plugin
BUNDLE_MECAB:BOOL=ON
 
// Choose the type of build, options are: None(CMAKE_CXX_FLAGS or
 CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel
CMAKE_BUILD_TYPE:STRING=RelWithDebInfo
 
// Install path prefix, prepended onto install directories.
CMAKE_INSTALL_PREFIX:PATH=/usr/local/mysql
 
// Set to true if this is a community build
COMMUNITY_BUILD:BOOL=ON
 
// Path to a library.
CRYPTO_LIBRARY:FILEPATH=/usr/lib64/libcrypto.so
 
//
DEB_CODENAME:STRING=
 
// Download boost from sourceforge.
DOWNLOAD_BOOST:BOOL=1
 
// Timeout in seconds when downloading boost.
DOWNLOAD_BOOST_TIMEOUT:STRING=600
 
// Enable profiling
ENABLED_PROFILING:BOOL=ON
 
// Enable debug sync (debug builds only)
ENABLE_DEBUG_SYNC:BOOL=ON
 
// Download and build 3rd party source code components, e.g. google mock
ENABLE_DOWNLOADS:BOOL=OFF
 
// Enable gcov (debug, Linux builds only)
ENABLE_GCOV:BOOL=OFF
 
// Enable gprof (optimized, Linux builds only)
ENABLE_GPROF:BOOL=OFF
 
// Enable SASL on InnoDB Memcached
ENABLE_MEMCACHED_SASL:BOOL=OFF
 
// Enable SASL on InnoDB Memcached
ENABLE_MEMCACHED_SASL_PWDB:BOOL=OFF
 
//  Selection of features. This option is deprecated
FEATURE_SET:STRING=community
 
// Installation directory layout. Options are: TARGZ (as in tar.gz installer), WIN (as in zip installer), STANDALONE, RPM, DEB, SVR4, FREEBSD, GLIBC, OSX, SLES
INSTALL_LAYOUT:STRING=STANDALONE
 
// Where to install mysqlclient.pc, defaults to lib/pkgconfig
INSTALL_PKGCONFIGDIR:PATH=
 
// Path to a file.
LOCAL_BOOST_DIR:FILEPATH=/var/lib/boost_1_59_0
 
// Path to a file.
LOCAL_BOOST_ZIP:FILEPATH=/var/lib/boost_1_59_0.tar.gz
 
// Mutex type: event, sys or futex
MUTEXTYPE:STRING=event
 
// default MySQL data directory
MYSQL_DATADIR:PATH=/data/mysql
 
// default MySQL keyring directory
MYSQL_KEYRINGDIR:PATH=/usr/local/mysql/keyring
 
// MySQL maintainer-specific development environment
MYSQL_MAINTAINER_MODE:BOOL=OFF
 
// Path to a file.
OPENSSL_INCLUDE_DIR:PATH=/usr/include
 
// Path to a library.
OPENSSL_LIBRARY:FILEPATH=/usr/lib64/libssl.so
 
// Path to a file.
OPENSSL_ROOT_DIR:PATH=/usr
 
// Support tracing of Optimizer
OPTIMIZER_TRACE:BOOL=ON
 
// PATH to MySQL TMP dir. Defaults to the P_tmpdir macro in <stdio.h>
TMPDIR:PATH=P_tmpdir
 
// Link ARCHIVE statically to the server
WITH_ARCHIVE_STORAGE_ENGINE:BOOL=ON
 
// Enable address sanitizer
WITH_ASAN:BOOL=OFF
 
// Link BLACKHOLE statically to the server
WITH_BLACKHOLE_STORAGE_ENGINE:BOOL=ON
 
// Path to boost sources: a directory, or a tarball to be unzipped.
WITH_BOOST:PATH=/var/lib
 
// Support for client-side protocol tracing plugins
WITH_CLIENT_PROTOCOL_TRACING:BOOL=ON
 
// Use dbug/safemutex
WITH_DEBUG:BOOL=OFF
 
// Use flags from cmake/build_configurations/compiler_options.cmake
WITH_DEFAULT_COMPILER_OPTIONS:BOOL=ON
 
// Use feature set in cmake/build_configurations/feature_set.cmake
WITH_DEFAULT_FEATURE_SET:BOOL=ON
 
// By default use bundled editline
WITH_EDITLINE:STRING=bundled
 
// Compile MySQL with embedded server
WITH_EMBEDDED_SERVER:BOOL=ON
 
// Generate shared version of embedded library (in addition to the static one)
WITH_EMBEDDED_SHARED_LIBRARY:BOOL=OFF
 
// Options are: none, complex, all
WITH_EXTRA_CHARSETS:STRING=all
 
// Link FEDERATED statically to the server
WITH_FEDERATED_STORAGE_ENGINE:BOOL=ON
 
// Enable extra InnoDB debug checks
WITH_INNODB_EXTRA_DEBUG:BOOL=OFF
 
//
WITH_INNODB_MEMCACHED:BOOL=OFF
 
// By default use bundled libevent on this platform
WITH_LIBEVENT:STRING=bundled
 
// Compile with tcp wrappers support
WITH_LIBWRAP:BOOL=0
 
// By default use bundled lz4 library
WITH_LZ4:STRING=bundled
 
// <empty> (disabled) | system (use os library) | </path/to/custom/installation> (use custom version)
WITH_MECAB:STRING=
 
// Enable memory sanitizer
WITH_MSAN:BOOL=OFF
 
// Link NGRAM_PARSER statically to the server
WITH_NGRAM_PARSER:BOOL=ON
 
// Explicitly set NUMA memory allocation policy
WITH_NUMA:BOOL=ON
 
// Link PARTITION statically to the server
WITH_PARTITION_STORAGE_ENGINE:BOOL=ON
 
// Generate PIC objects
WITH_PIC:BOOL=OFF
 
// Build additonal code(plugins) that is located in rapid directory
WITH_RAPID:BOOL=ON
 
//
WITH_SSL:STRING=system
 
// Enable installation of systemd support files
WITH_SYSTEMD:BOOL=OFF
 
// Have a built-in test protocol trace plugin in libmysql (requires WITH_CLIENT_PROTOCOL_TRACING option)
WITH_TEST_TRACE_PLUGIN:BOOL=OFF
 
// Enable undefined behavior sanitizer
WITH_UBSAN:BOOL=OFF
 
// Compile MySQL with unit tests
WITH_UNIT_TESTS:BOOL=ON
 
// Valgrind instrumentation
WITH_VALGRIND:BOOL=OFF
 
//
WITH_ZLIB:STRING=system
 
// Enable logging of protobuf messages
XPLUGIN_LOG_PROTOBUF:STRING=1

Centos 7环境下编译mysql 5.7的更多相关文章

  1. Centos 7环境下配置MySQL 5.7读写分离

    1.实验目的: 实现在Centos 7系统环境下,MySQL5.7读写分离. 2.实验条件: MySQL主服务器:Centos 7桌面环境,IP:10.10.11.31 MySQL从服务器:Cento ...

  2. CentOS 7+ 环境下安装MySQL

    在CentOS中默认安装有MariaDB,但是我们需要的是MySQL,安装MySQL可以覆盖MariaDB MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可 ...

  3. Centos 7环境下安装配置MySQL 5.7

    安装步骤为: 1.由于Centos 7版中已经移除MySQL rpm,因此需要到其官方网站上下载rpm,下载完成后,使用以下命令,来安装MySQL的rpm配置. rpm -ivh *****[注释:* ...

  4. centos环境下登录mysql报 ERROR 1045 (28000)怎么解决

    centos环境下登录mysql报 ERROR 1045 (28000)怎么解决 新入手一台虚拟机,Centos7系列的操作系统,安装mysql后,执行连接出现了Mysql ERROR 1045 (2 ...

  5. centos 6.5下安装mysql+nginx+redmine 3.1.0 笔记

    centos 6.5下安装mysql+nginx+redmine 3.1.0 笔记 目录[-] 过程 1.安装RVM 2.利用rvm安装 Ruby 1.9.3 并设为默认 3.安装rails 4.安装 ...

  6. Redhat环境下编译安装Google Bazel

    Redhat环境下编译安装bazel 作者:Jack47 目前Google Bazel没有提供各个操作系统下的二进制安装包,只提供源代码,需要我们自己编译安装,详情可以见我翻译的中文版Google B ...

  7. 【简书】在阿里云自带的CentOS + LAMP环境下部署一个Laravel项目

    在阿里云自带的CentOS + LAMP环境下部署一个Laravel项目 作者 DonnieZero 关注 2017.07.29 22:02* 字数 2218 阅读 5556评论 3喜欢 1赞赏 1 ...

  8. CentOS和Windows下配置MySQL远程访问的教程

    CentOS和Windows下配置MySQL远程访问的教程   一.前言 由于实验在云服务器上跑的结果不是很理想.所以,现在切换到局域网服务器.因此,需要重新配置 Windows 服务器和 CentO ...

  9. 不要着急改代码,先想想--centos 6.8下编译安装tmux

    诸位读者新年好,2017开年第一篇博客,请允许我先问候一下看到这篇博客的诸位.写博客是我2017年定下的目标之一,希望我会坚持下去. 最近打算尝试一下tmux这个神器,于是有了这一篇关于思维方式的Bl ...

随机推荐

  1. Spark在Yarn上运行Wordcount程序

    前提条件 1.CDH安装spark服务 2.下载IntelliJ IDEA编写WorkCount程序 3.上传到spark集群执行 一.下载IntellJ IDEA编写Java程序 1.下载IDEA ...

  2. 7.2.12. MySQL如何优化ORDER BY

    在某些情况中,MySQL可以使用一个索引来满足ORDER BY子句,而不需要额外的排序. 即使ORDER BY不确切匹配索引,只要WHERE子句中的所有未使用的索引部分和所有额外的ORDER BY 列 ...

  3. C# Winform 界面中各控件随着窗口大小变化

    在做一项工程中,由于不确定目标平台的分辨率,而正常使用要求铺满整个屏幕,所以界面中的各个控件必须能够适应窗口的变化. 首先想到的就是控件的百分比布局,但是再尝试写了几个控件的Location和Size ...

  4. 配置fabric-crashlytics教程

    1. 注册账户 登录网站  https://try.crashlytics.com/ 来注册新的账户,审核通过时间为几个小时或者1到2天不等.然后注册时候输入的邮箱就会收到如下的邀请涵 2. acco ...

  5. 分享:一款前端布局工具(alloydesigner)

    困扰 设计师给出静态的高保真图片, 需要前端工程师按照高保真图,进行html编码. 前端工程师, 一般工作方法为: 打开图片,一边看下图片, 一边编写相应的html代码. 这样有两个问题: 1. 前端 ...

  6. 在xcode运行编译时,编译成功,但项目中显示缺少该文件,这是只要关闭重启xcode即可。

    在xcode运行编译时,编译成功,但项目中显示缺少该文件,这是只要关闭重启xcode即可.

  7. js接受url参数

    1.正则表达式 function getQueryString(name) { var reg = new RegExp("(^|&)" + name + "=( ...

  8. dotnetnuke peek. glance.

    /**** 15:59:39.05 ***/ use dotnetnuke to create websites: 1. install 2. create webpage template 3. c ...

  9. 我们应该如何去了解JavaScript引擎的工作原理

    “读了你的几篇关于JS(变量对象.作用域.上下文.执行代码)的文章,我个人觉得有点抽象,难以深刻理解.我想请教下通过什么途径能够深入点的了解javascript解析引擎在执行代码前后是怎么工作的,ec ...

  10. socket.io稳定性及事件测试

    socket.io测试报告 1.socekt.io能坚持多久 将服务器上的socekt.io代码从早上9:30分开始运行到晚上18点,每100毫秒发送一条数据,数据大概15个字符,同时开启5个连接 结 ...