由于CentOS 6 现在yum源的mysql-server 版本还是5.1 的,已经比较老了
况且后续服务可能需要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
Formats | Description | Default | Introduced | Removed |
---|---|---|---|---|
BUILD_CONFIG |
Use same build options as official releases | |||
CMAKE_BUILD_TYPE |
Type of build to produce | RelWithDebInfo |
||
CMAKE_CXX_FLAGS |
Flags for C++ Compiler | |||
CMAKE_C_FLAGS |
Flags for C Compiler | |||
CMAKE_INSTALL_PREFIX |
Installation base directory | /usr/local/mysql |
||
COMPILATION_COMMENT |
Comment about compilation environment | |||
CPACK_MONOLITHIC_INSTALL |
Whether package build produces single file | OFF |
||
DEFAULT_CHARSET |
The default server character set | latin1 |
||
DEFAULT_COLLATION |
The default server collation | latin1_swedish_ci |
||
-DWITH_SYMVER16 |
Whether libmysqlclient.so.18 contains both symver 16 and 18 symbols. | OFF |
5.6.31 | |
ENABLED_LOCAL_INFILE |
Whether to enable LOCAL for LOAD DATA INFILE | OFF |
||
ENABLED_PROFILING |
Whether to enable query profiling code | ON |
||
ENABLE_DEBUG_SYNC |
Whether to enable Debug Sync support | ON |
||
ENABLE_DOWNLOADS |
Whether to download optional files | OFF |
||
ENABLE_DTRACE |
Whether to include DTrace support | |||
ENABLE_GCOV |
Whether to include gcov support | 5.6.3 | ||
ENABLE_GPROF |
Enable gprof (optimized Linux builds only) | OFF |
5.6.6 | |
IGNORE_AIO_CHECK |
With -DBUILD_CONFIG=mysql_release, ignore libaio check | OFF |
5.6.1 | |
INNODB_PAGE_ATOMIC_REF_COUNT |
Enable or disable atomic page reference counting | ON |
5.6.16 | |
INSTALL_BINDIR |
User executables directory | PREFIX/bin |
||
INSTALL_DOCDIR |
Documentation directory | PREFIX/docs |
||
INSTALL_DOCREADMEDIR |
README file directory | PREFIX |
||
INSTALL_INCLUDEDIR |
Header file directory | PREFIX/include |
||
INSTALL_INFODIR |
Info file directory | PREFIX/docs |
||
INSTALL_LAYOUT |
Select predefined installation layout | STANDALONE |
||
INSTALL_LIBDIR |
Library file directory | PREFIX/lib |
||
INSTALL_MANDIR |
Manual page directory | PREFIX/man |
||
INSTALL_MYSQLSHAREDIR |
Shared data directory | PREFIX/share |
||
INSTALL_MYSQLTESTDIR |
mysql-test directory | PREFIX/mysql-test |
||
INSTALL_PLUGINDIR |
Plugin directory | PREFIX/lib/plugin |
||
INSTALL_SBINDIR |
Server executable directory | PREFIX/bin |
||
INSTALL_SCRIPTDIR |
Scripts directory | PREFIX/scripts |
||
INSTALL_SHAREDIR |
aclocal/mysql.m4 installation directory | PREFIX/share |
||
INSTALL_SQLBENCHDIR |
sql-bench directory | PREFIX |
||
INSTALL_SUPPORTFILESDIR |
Extra support files directory | PREFIX/support-files |
||
MEMCACHED_HOME |
Path to memcached | [none] |
||
MYSQL_DATADIR |
Data directory | |||
MYSQL_MAINTAINER_MODE |
Whether to enable MySQL maintainer-specific development environment | OFF |
||
MYSQL_PROJECT_NAME |
Windows/OS X project name | 3306 |
5.6.5 | |
MYSQL_TCP_PORT |
TCP/IP port number | 3306 |
||
MYSQL_UNIX_ADDR |
Unix socket file | /tmp/mysql.sock |
||
ODBC_INCLUDES |
ODBC includes directory | |||
ODBC_LIB_DIR |
ODBC library directory | |||
OPTIMIZER_TRACE |
Whether to support optimizer tracing | 5.6.3 | ||
SUNPRO_CXX_LIBRARY |
Client link library on Solaris 10+ | 5.6.20 | ||
SYSCONFDIR |
Option file directory | |||
TMPDIR |
tmpdir default value | 5.6.16 | ||
WITHOUT_SERVER |
Do not build the server | OFF |
||
WITHOUT_xxx_STORAGE_ENGINE |
Exclude storage engine xxx from build | |||
WITH_ASAN |
Enable AddressSanitizer | OFF |
5.6.15 | |
WITH_BUNDLED_LIBEVENT |
Use bundled libevent when building ndbmemcache | ON |
||
WITH_BUNDLED_MEMCACHED |
Use bundled memcached when building ndbmemcache | ON |
||
WITH_CLASSPATH |
Classpath to use when building MySQL Cluster Connector for Java. Default is an empty string. | |||
WITH_DEBUG |
Whether to include debugging support | OFF |
||
WITH_DEFAULT_COMPILER_OPTIONS |
Whether to use default compiler options | ON |
5.6.6 | |
WITH_DEFAULT_FEATURE_SET |
Whether to use default feature set | ON |
5.6.6 | |
WITH_EDITLINE |
Which libedit/editline library to use | bundled |
5.6.12 | |
WITH_EMBEDDED_SERVER |
Whether to build embedded server | OFF |
||
WITH_EMBEDDED_SHARED_LIBRARY |
Whether to build a shared embedded server library | OFF |
5.6.17 | |
WITH_ERROR_INSERT |
Enable error injection in the NDB storage engine. Should not be used for building binaries intended for production. | OFF |
||
WITH_EXTRA_CHARSETS |
Which extra character sets to include | all |
||
WITH_INNODB_MEMCACHED |
Whether to generate memcached shared libraries. | OFF |
||
WITH_LIBEDIT |
Use bundled libedit library | ON |
5.6.12 | |
WITH_LIBEVENT |
Which libevent library to use | bundled |
5.6.6 | |
WITH_LIBWRAP |
Whether to include libwrap (TCP wrappers) support | OFF |
||
WITH_NDBCLUSTER |
Build the NDB storage engine; alias for WITH_NDBCLUSTER_STORAGE_ENGINE | ON |
||
WITH_NDBCLUSTER_STORAGE_ENGINE |
Build the NDB storage engine | ON |
||
WITH_NDBMTD |
Build multi-threaded data node. | ON |
||
WITH_NDB_BINLOG |
Enable binary logging by default by mysqld. | ON |
||
WITH_NDB_DEBUG |
Produce a debug build for testing or troubleshooting. | OFF |
||
WITH_NDB_JAVA |
Enable building of Java and ClusterJ support. Enabled by default. Supported in MySQL Cluster only. | ON |
||
WITH_NDB_PORT |
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] |
||
WITH_NDB_TEST |
Include NDB API test programs. | OFF |
||
WITH_READLINE |
Use bundled readline library | OFF |
5.6.5 | |
WITH_SSL |
Type of SSL support | bundled |
||
WITH_UNIXODBC |
Enable unixODBC support | OFF |
||
WITH_VALGRIND |
Whether to compile in Valgrind header files | OFF |
||
WITH_ZLIB |
Type of zlib support | bundled |
||
WITH_xxx_STORAGE_ENGINE |
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 ..........
编译的参数可以参考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
明确写出mysql的安装目录,数据库的存放目录,默认tcp端口,socket文件目录
# service mysqld restart
基本安装就完成.