由于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时,此文档更是不得不看。编译时我习惯于一些选项 (比如安装位置)不按默认的来,因为如果按默认选项出了问题,更不好解决(因为到时你不仅需要知道到底有选项有何含义还要知道默认的是什么,反而更麻 烦)。
# 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 #默认字符集
-- 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(‘123.com‘); 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
基本安装就完成.
本文出自 “Professor哥” 博客,转载请与作者联系!
源码安装 MySQL Community Server 5.6.26
原文地址:http://professor.blog.51cto.com/996189/1695769