首先在编译之前,我们要了解相关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. 一个ICMP单元

    unit ICMPUtils; interface {$IFDEF VER80} { This source file is *NOT* compatible with Delphi 1 becaus ...

  2. chrome下input[type=text]的placeholder不垂直居中的问题解决

    http://blog.csdn.net/do_it__/article/details/6789699 <input type="text" placeholder=&qu ...

  3. k8s入门系列之集群安装篇

    关于kubernetes组件的详解介绍,请阅读上一篇文章<k8s入门系列之介绍篇> Kubernetes集群安装部署 •Kubernetes集群组件: - etcd 一个高可用的K/V键值 ...

  4. iTween研究院之学习笔记Move移动篇

             最近项目中需要加入一些模型移动的小动画,学习过程中发现了iTween这个类库.它主要的功能就是处理模型从起始点到结束点之间运动的轨迹.(移动,旋转,音频,路径,摄像机等)它是一个开源 ...

  5. Windows Server 2008 R2 创建辅助DNS服务器并接管主要DNS服务器

    公司需求: Zhuyu公司局域网有一台主要DNS服务器,经领导讨论需要规划安装一台辅助DNS服务器备用. 功能需求: 当主要DNS服务器宕机或系统崩溃,辅助DNS服务器能接管主要DNS服务器工作,并且 ...

  6. jdk环境变量

    exportJAVA_HOME=/opt/jdk1.8.0_92 exportJRE_HOME=${JAVA_HOME}/jre   exportCLASSPATH=.:${JAVA_HOME}/li ...

  7. windows2003服务器mysql每天定时备份

    1.php利用mysqldump备份数据库,代码如下: <?php /** * 数据库备份 */ $sqlname = $argv[1]; //接受bat或cmd传过来的第一个参数 要备份的数据 ...

  8. 深入研究虚拟机之垃圾收集(GC)算法实现

    一.         What, Why 1.   GC是什么?为什么需要GC GC,全写是Garbage Collection , 即垃圾回收.GC是一种自动内存管理机制.通常我们在需要时手动的分配 ...

  9. !! 据说年薪30万的Android程序员必须知道事

    http://www.th7.cn/Program/Android/201512/742423.shtml Android中国开发精英 目前包括: Android开源项目第一篇——个性化控件(View ...

  10. storyboard

    一,代码动态改写 1,一般程序启动就自动执行 main.storyboard 也可以在AppDelegate改写 - (BOOL)application:(UIApplication *)applic ...