由于CentOS 6 现在yum源的mysql-server 版本还是5.1 的,已经比较老了

wKiom1X6gcyx3LpNAAFK6JcM1FY162.jpg

况且后续服务可能需要mysql的头文件, yum安装的没有找不到头文件,索性就编译安装.


MySQL官网是: http://dev.mysql.com/downloads/mysql/ 

1,直接下载源码:

说明:MySQL 5.5的编译工具由Autotool转变为了cmake(有关于更多关于cmake的信息,请大家自行google了解)。MySQL团队也撰写了一篇Autotools to CMake Transition Guide , 本文将要列出的各个编译选项以及更多的编译选项的说明可以参考该文档。在troubleshooting时,此文档更是不得不看。编译时我习惯于一些选项 (比如安装位置)不按默认的来,因为如果按默认选项出了问题,更不好解决(因为到时你不仅需要知道到底有选项有何含义还要知道默认的是什么,反而更麻 烦)。

cmake 参数说明请参阅官方文档 http://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html 


FormatsDescriptionDefaultIntroducedRemoved
BUILD_CONFIGUse same build options as official releases   
CMAKE_BUILD_TYPEType of build to produceRelWithDebInfo  
CMAKE_CXX_FLAGSFlags for C++ Compiler   
CMAKE_C_FLAGSFlags for C Compiler   
CMAKE_INSTALL_PREFIXInstallation base directory/usr/local/mysql  
COMPILATION_COMMENTComment about compilation environment   
CPACK_MONOLITHIC_INSTALLWhether package build produces single fileOFF  
DEFAULT_CHARSETThe default server character setlatin1  
DEFAULT_COLLATIONThe default server collationlatin1_swedish_ci  
-DWITH_SYMVER16Whether libmysqlclient.so.18 contains both symver 16 and 18 symbols.OFF5.6.31 
ENABLED_LOCAL_INFILEWhether to enable LOCAL for LOAD DATA INFILEOFF  
ENABLED_PROFILINGWhether to enable query profiling codeON  
ENABLE_DEBUG_SYNCWhether to enable Debug Sync supportON  
ENABLE_DOWNLOADSWhether to download optional filesOFF  
ENABLE_DTRACEWhether to include DTrace support   
ENABLE_GCOVWhether to include gcov support 5.6.3 
ENABLE_GPROFEnable gprof (optimized Linux builds only)OFF5.6.6 
IGNORE_AIO_CHECKWith -DBUILD_CONFIG=mysql_release, ignore libaio checkOFF5.6.1 
INNODB_PAGE_ATOMIC_REF_COUNTEnable or disable atomic page reference countingON5.6.16 
INSTALL_BINDIRUser executables directoryPREFIX/bin  
INSTALL_DOCDIRDocumentation directoryPREFIX/docs  
INSTALL_DOCREADMEDIRREADME file directoryPREFIX  
INSTALL_INCLUDEDIRHeader file directoryPREFIX/include  
INSTALL_INFODIRInfo file directoryPREFIX/docs  
INSTALL_LAYOUTSelect predefined installation layoutSTANDALONE  
INSTALL_LIBDIRLibrary file directoryPREFIX/lib  
INSTALL_MANDIRManual page directoryPREFIX/man  
INSTALL_MYSQLSHAREDIRShared data directoryPREFIX/share  
INSTALL_MYSQLTESTDIRmysql-test directoryPREFIX/mysql-test  
INSTALL_PLUGINDIRPlugin directoryPREFIX/lib/plugin  
INSTALL_SBINDIRServer executable directoryPREFIX/bin  
INSTALL_SCRIPTDIRScripts directoryPREFIX/scripts  
INSTALL_SHAREDIRaclocal/mysql.m4 installation directoryPREFIX/share  
INSTALL_SQLBENCHDIRsql-bench directoryPREFIX  
INSTALL_SUPPORTFILESDIRExtra support files directoryPREFIX/support-files  
MEMCACHED_HOMEPath to memcached[none]  
MYSQL_DATADIRData directory   
MYSQL_MAINTAINER_MODEWhether to enable MySQL maintainer-specific development environmentOFF  
MYSQL_PROJECT_NAMEWindows/OS X project name33065.6.5 
MYSQL_TCP_PORTTCP/IP port number3306  
MYSQL_UNIX_ADDRUnix socket file/tmp/mysql.sock  
ODBC_INCLUDESODBC includes directory   
ODBC_LIB_DIRODBC library directory   
OPTIMIZER_TRACEWhether to support optimizer tracing 5.6.3 
SUNPRO_CXX_LIBRARYClient link library on Solaris 10+ 5.6.20 
SYSCONFDIROption file directory   
TMPDIRtmpdir default value 5.6.16 
WITHOUT_SERVERDo not build the serverOFF  
WITHOUT_xxx_STORAGE_ENGINEExclude storage engine xxx from build   
WITH_ASANEnable AddressSanitizerOFF5.6.15 
WITH_BUNDLED_LIBEVENTUse bundled libevent when building ndbmemcacheON  
WITH_BUNDLED_MEMCACHEDUse bundled memcached when building ndbmemcacheON  
WITH_CLASSPATHClasspath to use when building MySQL Cluster Connector for Java. Default is an empty string.
  
WITH_DEBUGWhether to include debugging supportOFF  
WITH_DEFAULT_COMPILER_OPTIONSWhether to use default compiler optionsON5.6.6 
WITH_DEFAULT_FEATURE_SETWhether to use default feature setON5.6.6 
WITH_EDITLINEWhich libedit/editline library to usebundled5.6.12 
WITH_EMBEDDED_SERVERWhether to build embedded serverOFF  
WITH_EMBEDDED_SHARED_LIBRARYWhether to build a shared embedded server libraryOFF5.6.17 
WITH_ERROR_INSERTEnable error injection in the NDB storage engine. Should not be used for building binaries intended for production.OFF  
WITH_EXTRA_CHARSETSWhich extra character sets to includeall  
WITH_INNODB_MEMCACHEDWhether to generate memcached shared libraries.OFF  
WITH_LIBEDITUse bundled libedit libraryON 5.6.12
WITH_LIBEVENTWhich libevent library to usebundled5.6.6 
WITH_LIBWRAPWhether to include libwrap (TCP wrappers) supportOFF  
WITH_NDBCLUSTERBuild the NDB storage engine; alias for WITH_NDBCLUSTER_STORAGE_ENGINEON  
WITH_NDBCLUSTER_STORAGE_ENGINEBuild the NDB storage engineON  
WITH_NDBMTDBuild multi-threaded data node.ON  
WITH_NDB_BINLOGEnable binary logging by default by mysqld.ON  
WITH_NDB_DEBUGProduce a debug build for testing or troubleshooting.OFF  
WITH_NDB_JAVAEnable building of Java and ClusterJ support. Enabled by default. Supported in MySQL Cluster only.ON  
WITH_NDB_PORTDefault port used by a management server built with this option. If this option was not used to build it, the management server's default port is 1186.[none]  
WITH_NDB_TESTInclude NDB API test programs.OFF  
WITH_READLINEUse bundled readline libraryOFF 5.6.5
WITH_SSLType of SSL supportbundled  
WITH_UNIXODBCEnable unixODBC supportOFF  
WITH_VALGRINDWhether to compile in Valgrind header filesOFF  
WITH_ZLIBType of zlib supportbundled  
WITH_xxx_STORAGE_ENGINECompile storage engine xxx statically into server   




# wget # groupadd -r mysql
# useradd -M -r -G mysql -s /sbin/nologin mysql
# tar xf  mysql-5.6.26.tar.gz 
# cd mysql-5.6.26
# yum install gcc gcc-c++ cmake  make ncurses ncurses-devel readline-devel openssl-devel  pcre-devel zlib-devel libxml2-devel
# cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql5.6.25 \   #mysql安装路径
-DMYSQL_DATADIR=/var/mysqldb  \     #数据文件存放位置
-DSYSCONFDIR=/etc              \  #my.cnf配置文件路径
-DWITH_MYISAM_STORAGE_ENGINE=1    \      #支持MyIASM引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1 \     #支持InnoDB引擎
-DWITH_MEMORY_STORAGE_ENGINE=1 \      #支持Memory引擎
-DWITH_READLINE=1     \          #命令行文本整理
-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock    \   #连接数据库socket路径
-DMYSQL_TCP_PORT=3306    \            #端口
-DENABLED_LOCAL_INFILE=1    \       #允许从本地文件中导入数据
-DWITH_PARTITION_STORAGE_ENGINE=1  \   #安装支持数据库分区表
-DEXTRA_CHARSETS=all  \             #安装所有的字符集
-DDEFAULT_CHARSET=utf8    \      #默认字符utf-8
-DDEFAULT_COLLATION=utf8_general_ci        #默认字符集(ci不区分大小写)
-- Running cmake version 2.8.12.2
-- Could NOT find Git (missing:  GIT_EXECUTABLE) 
-- The C compiler identification is GNU 4.4.7
-- The CXX compiler identification is GNU 4.4.7
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
..................
-- COMPILE_DEFINITIONS: HAVE_CONFIG_H
-- 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
CMake Warning:
  Manually-specified variables were not used by the project:

    WITH_MEMORY_STORAGE_ENGINE
    WITH_READLINE


-- Build files have been written to: /root/mysql-5.6.26
# make -j 4 && make install
Scanning dependencies of target INFO_BIN
[  0%] Built target INFO_BIN
Scanning dependencies of target INFO_SRC
[  0%] Built target INFO_SRC
Scanning dependencies of target abi_check
[  0%] Built target abi_check
Scanning dependencies of target zlib
[  0%] Building C object zlib/CMakeFiles/zlib.dir/adler32.c.o
[  0%] Building C object zlib/CMakeFiles/zlib.dir/compress.c.o
[  0%] Building C object zlib/CMakeFiles/zlib.dir/crc32.c.o
[  0%] Building C object zlib/CMakeFiles/zlib.dir/deflate.c.o
[  0%] Building C object zlib/CMakeFiles/zlib.dir/gzio.c.o
[  0%] Building C object zlib/CMakeFiles/zlib.dir/infback.c.o
[  0%] Building C object zlib/CMakeFiles/zlib.dir/inffast.c.o
[  0%] Building C object zlib/CMakeFiles/zlib.dir/inflate.c.o
[  0%] Building C object zlib/CMakeFiles/zlib.dir/inftrees.c.o
[  0%] Building C object zlib/CMakeFiles/zlib.dir/trees.c.o
[  0%] Building C object zlib/CMakeFiles/zlib.dir/uncompr.c.o
[  1%] Building C object zlib/CMakeFiles/zlib.dir/zutil.c.o
Linking C static library libzlib.a
[  1%] Built target zlib
Scanning dependencies of target yassl
[  1%] Building CXX object extra/yassl/CMakeFiles/yassl.dir/src/buffer.cpp.o
[  1%] Building CXX object extra/yassl/CMakeFiles/yassl.dir/src/cert_wrapper.cpp.o
[  1%] Building CXX object extra/yassl/CMakeFiles/yassl.dir/src/crypto_wrapper.cpp.o
[  1%] Building CXX object extra/yassl/CMakeFiles/yassl.dir/src/handshake.cpp.o
[  2%] Building CXX object extra/yassl/CMakeFiles/yassl.dir/src/yassl_int.cpp.o
[  2%] Building C object extra/yassl/CMakeFiles/yassl.dir/__/__/client/get_password.c.o
Linking CXX static library libyassl.a
[  2%] Built target yassl
Scanning dependencies of target taocrypt
[  2%] Building CXX object extra/yassl/taocrypt/CMakeFiles/taocrypt.dir/src/aes.cpp.o
[  2%] Building CXX object extra/yassl/taocrypt/CMakeFiles/taocrypt.dir/src/aestables.cpp.o
[  2%] Building CXX object extra/yassl/taocrypt/CMakeFiles/taocrypt.dir/src/algebra.cpp.o
[  2%] Building CXX object extra/yassl/taocrypt/CMakeFiles/taocrypt.dir/src/arc4.cpp.o
[  3%] Building CXX object extra/yassl/taocrypt/CMakeFiles/taocrypt.dir/src/asn.cpp.o
[ 20%] Built target simple-t
[ 20%] Built target skip-t
[ 20%] Built target skip_all-t
[ 20%] Built target todo-t
[ 20%] Built target basic-t
[ 20%] [ 20%] Built target my_print_defaults
Built target mysql_waitpid
[ 21%] Built target innochecksum
[ 21%] Built target replace
[ 22%] [ 22%] Built target resolve_stack_dump
Built target resolveip
[ 22%] [ 22%] Built target mysql_tzinfo_to_sql
[ 30%] Built target perfschema
[ 35%] Built target perfschema_embedded
[ 35%] Built target federated
[ 37%] Built target myisammrg

[ 52%] Built target pfs_instr-t
[ 52%] Built target pfs_instr_class-oom-t
[ 52%] [ 52%] Built target pfs_instr_class-t
Built target pfs_misc-t
[ 59%] Built target myisam_embedded
[ 59%] Built target myisam_ftdump
[ 59%] Built target myisamchk
[ 59%] Built target myisamlog
[ 59%] Built target myisampack
[ 59%] Built target federated_embedded
[ 59%] Built target blackhole_embedded
[ 61%] Built target myisammrg_embedded
[ 69%] [ 69%] Built target innobase_embedded
Built target auth
[ 69%] Built target auth_socket
[ 69%] Built target auth_test
..........


编译的参数可以参考http://dev.mysql.com/doc/refman/5.5/en/source-configuration-options.html 



整个过程需要30分钟左右……漫长的等待



2, 配置MySQL 5.6

# chown -R mysql:mysql /usr/local/mysql5.6.25    //修改MySQL安装目录的所属用户组
# cd /usr/local/mysql5.6.25
# scripts/mysql_install_db --basedir=/usr/local/mysql5.6.26/ --datadir=/var/mysqldb/ --user=mysql        //初始化MySQL
# cp support-files/mysql.server /etc/init.d/mysqld    //拷贝服务脚本到系统init.d目录
# chkconfig --add mysqld                    //添加启动列表
# chkconfig mysqld on                        //设置开机启动服务
# service mysqld start                        //手动启动mysqld 服务


MySQL 服务启动后,默认管理账户是root ,密码为空

# cd bin/
# mysql        //默认账户是root  密码为空


接下来添加mysql 程序目录的环境变量  或者  添加软连接

# echo 'export PATH=${PATH}:/usr/local/mysql5.6.26/bin/' >> /etc/profile
# source /etc/profile

或者

# ln -s /usr/local/mysql5.6.26/bin/*  /usr/bin/


3, 修改数据库默认root密码

# mysql -u root
mysql> 
mysql> SET PASSWORD=PASSWORD('passwd');
Query OK, 0 rows affected (0.00 sec)


4, 配置my.cnf

mysql的配置文件,这是很重要的一步,配置得当以后就不需要在启动时写上大段的参数了。

首先应该知道:MySQL寻找配置文件的路径以及顺序。最开始检索的位置是/etc/my.cnf之后是/etc/mysql/my.cnf因此我们要做的就是在这两个地方之一建立配置文件my.cnf。MySQL为我们准备了几种不同方案的默认配置文件(在mysql的安装目录中 support-files/目录下有个 my-default.cnf的文件),因此我们可以复制一份到上述的位置

# cp /usr/local/mysql5.6.26/support-files/my-default.cnf /etc/my.cnf
# vim /etc/my.cnf

wKioL1X6qDPSuOnpAABuWLQWOp0083.jpg

明确写出mysql的安装目录,数据库的存放目录,默认tcp端口,socket文件目录

# service mysqld restart


基本安装就完成.