由于CentOS 6 现在yum源的mysql-server 版本还是5.1 的,已经比较老了
况且后续服务可能需要mysql的头文件, yum安装的没有找不到头文件,索性就编译安装.
1,直接下载源码:
说明:MySQL 5.5的编译工具由Autotool转变为了cmake(有关于更多关于cmake的信息,请大家自行google了解)。MySQL团队也撰写了一篇Autotools to CMake Transition Guide , 本文将要列出的各个编译选项以及更多的编译选项的说明可以参考该文档。在troubleshooting时,此文档更是不得不看。编译时我习惯于一些选项 (比如安装位置)不按默认的来,因为如果按默认选项出了问题,更不好解决(因为到时你不仅需要知道到底有选项有何含义还要知道默认的是什么,反而更麻 烦)。
FormatsDescriptionDefaultIntroducedRemovedUse same build options as official releases
Type of build to produceRelWithDebInfo
Flags for C++ Compiler
Flags for C Compiler
Installation base directory/usr/local/mysql
Comment about compilation environment
Whether package build produces single fileOFF
The default server character setlatin1
The default server collationlatin1_swedish_ci
Whether libmysqlclient.so.18 contains both symver 16 and 18 symbols.OFF5.6.31
Whether to enable LOCAL for LOAD DATA INFILEOFF
Whether to enable query profiling codeON
Whether to enable Debug Sync supportON
Whether to download optional filesOFF
Whether to include DTrace support
Whether to include gcov support5.6.3
Enable gprof (optimized Linux builds only)OFF5.6.6
With -DBUILD_CONFIG=mysql_release, ignore libaio checkOFF5.6.1
Enable or disable atomic page reference countingON5.6.16
User executables directoryPREFIX/bin
Documentation directoryPREFIX/docs
README file directoryPREFIX
Header file directoryPREFIX/include
Info file directoryPREFIX/docs
Select predefined installation layoutSTANDALONE
Library file directoryPREFIX/lib
Manual page directoryPREFIX/man
Shared data directoryPREFIX/share
mysql-test directoryPREFIX/mysql-test
Plugin directoryPREFIX/lib/plugin
Server executable directoryPREFIX/bin
Scripts directoryPREFIX/scripts
aclocal/mysql.m4 installation directoryPREFIX/share
sql-bench directoryPREFIX
Extra support files directoryPREFIX/support-files
Path to memcached[none]
Data directory
Whether to enable MySQL maintainer-specific development environmentOFF
Windows/OS X project name33065.6.5
TCP/IP port number3306
Unix socket file/tmp/mysql.sock
ODBC includes directory
ODBC library directory
Whether to support optimizer tracing5.6.3
Client link library on Solaris 10+5.6.20
Option file directory
tmpdir default value5.6.16
Do not build the serverOFF
Exclude storage engine xxx from build
Enable AddressSanitizerOFF5.6.15
Use bundled libevent when building ndbmemcacheON
Use bundled memcached when building ndbmemcacheON
Classpath to use when building MySQL Cluster Connector for Java. Default is an empty string.
Whether to include debugging supportOFF
Whether to use default compiler optionsON5.6.6
Whether to use default feature setON5.6.6
Which libedit/editline library to usebundled5.6.12
Whether to build embedded serverOFF
Whether to build a shared embedded server libraryOFF5.6.17
Enable error injection in the NDB storage engine. Should not be used for building binaries intended for production.OFF
Which extra character sets to includeall
Whether to generate memcached shared libraries.OFF
Use bundled libedit libraryON5.6.12
Which libevent library to usebundled5.6.6
Whether to include libwrap (TCP wrappers) supportOFF
Build the NDB storage engine; alias for WITH_NDBCLUSTER_STORAGE_ENGINEON
Build the NDB storage engineON
Build multi-threaded data node.ON
Enable binary logging by default by mysqld.ON
Produce a debug build for testing or troubleshooting.OFF
Enable building of Java and ClusterJ support. Enabled by default. Supported in MySQL Cluster only.ON
Default 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]
Include NDB API test programs.OFF
Use bundled readline libraryOFF5.6.5
Type of SSL supportbundled
Enable unixODBC supportOFF
Whether to compile in Valgrind header filesOFF
Type of zlib supportbundled
Compile 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
..........
整个过程需要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
明确写出mysql的安装目录,数据库的存放目录,默认tcp端口,socket文件目录# service mysqld restart
基本安装就完成.