CentOS7下源码安装5.6.23
清理CentOS7下的MariaDB。
[root@localhost ~]#rpm -qa | gremp mariadb
[root@localhost ~]# rpm -e --nodeps mariadb.x86_64 1
:5.5.41-2.el7_0
- 下载源码
[root@localhost ~]# wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.23.tar.gz
2.解压
[root@localhost ~]# tar zxvf mysql-5.6.23.tar.gz
3.安装必要的包
[root@localhost ~]# sudo yum install cmake gcc-c++ ncurses-devel perl-Data-Dumper
已加载插件:fastestmirror, langpacks
base | 3.6 kB 00:00
extras | 3.4 kB 00:00
updates | 3.4 kB 00:00
(1/2): extras/7/x86_64/primary_db | 117 kB 00:00
(2/2): updates/7/x86_64/primary_db | 3.9 MB 00:01
Determining fastest mirrors
* base: mirrors.163.com
* extras: mirrors.skyshe.cn
* updates: mirrors.163.com
软件包 perl-Data-Dumper-2.145-3.el7.x86_64 已安装并且是最新版本
正在解决依赖关系
--> 正在检查事务
---> 软件包 cmake.x86_64.0.2.8.11-5.el7 将被 安装
---> 软件包 gcc-c++.x86_64.0.4.8.5-4.el7 将被 安装
--> 正在处理依赖关系 libstdc++-devel = 4.8.5-4.el7,它被软件包 gcc-c++-4.8.5-4.el7.x86_64 需要
--> 正在处理依赖关系 libstdc++ = 4.8.5-4.el7,它被软件包 gcc-c++-4.8.5-4.el7.x86_64 需要
--> 正在处理依赖关系 gcc = 4.8.5-4.el7,它被软件包 gcc-c++-4.8.5-4.el7.x86_64 需要
--> 正在处理依赖关系 libmpc.so.3()(64bit),它被软件包 gcc-c++-4.8.5-4.el7.x86_64 需要
---> 软件包 ncurses-devel.x86_64.0.5.9-13.20130511.el7 将被 安装
--> 正在检查事务
---> 软件包 gcc.x86_64.0.4.8.5-4.el7 将被 安装
--> 正在处理依赖关系 libgomp = 4.8.5-4.el7,它被软件包 gcc-4.8.5-4.el7.x86_64 需要
--> 正在处理依赖关系 cpp = 4.8.5-4.el7,它被软件包 gcc-4.8.5-4.el7.x86_64 需要
--> 正在处理依赖关系 libgcc >= 4.8.5-4.el7,它被软件包 gcc-4.8.5-4.el7.x86_64 需要
---> 软件包 libmpc.x86_64.0.1.0.1-3.el7 将被 安装
---> 软件包 libstdc++.x86_64.0.4.8.3-9.el7 将被 升级
---> 软件包 libstdc++.x86_64.0.4.8.5-4.el7 将被 更新
---> 软件包 libstdc++-devel.x86_64.0.4.8.5-4.el7 将被 安装
--> 正在检查事务
---> 软件包 cpp.x86_64.0.4.8.5-4.el7 将被 安装
---> 软件包 libgcc.x86_64.0.4.8.3-9.el7 将被 升级
---> 软件包 libgcc.x86_64.0.4.8.5-4.el7 将被 更新
---> 软件包 libgomp.x86_64.0.4.8.3-9.el7 将被 升级
---> 软件包 libgomp.x86_64.0.4.8.5-4.el7 将被 更新
--> 解决依赖关系完成
依赖关系解决
=====================================================
Package 架构 版本 源 大小
=====================================================
正在安装:
cmake x86_64 2.8.11-5.el7 base 6.7 M
gcc-c++ x86_64 4.8.5-4.el7 base 7.2 M
ncurses-devel x86_64 5.9-13.20130511.el7 base 713 k
为依赖而安装:
cpp x86_64 4.8.5-4.el7 base 5.9 M
gcc x86_64 4.8.5-4.el7 base 16 M
libmpc x86_64 1.0.1-3.el7 base 51 k
libstdc++-devel x86_64 4.8.5-4.el7 base 1.5 M
为依赖而更新:
libgcc x86_64 4.8.5-4.el7 base 95 k
libgomp x86_64 4.8.5-4.el7 base 130 k
libstdc++ x86_64 4.8.5-4.el7 base 298 k
事务概要
=====================================================
安装 3 软件包 (+4 依赖软件包)
升级 ( 3 依赖软件包)
总计:39 M
总下载量:38 M
Is this ok [y/d/N]: y
Downloading packages:
(1/7): libmpc-1.0.1-3.el7.x86_64.rpm | 51 kB 00:00
(2/7): gcc-c++-4.8.5-4.el7.x86_64.rpm | 7.2 MB 00:03
(3/7): libstdc++-devel-4.8.5-4.el7.x86_64.rpm | 1.5 MB 00:03
(4/7): ncurses-devel-5.9-13.20130511.el7.x86_64.rpm | 713 kB 00:00
(5/7): cpp-4.8.5-4.el7.x86_64.rpm | 5.9 MB 00:04
(6/7): cmake-2.8.11-5.el7.x86_64.rpm | 6.7 MB 00:05
(7/7): gcc-4.8.5-4.el7.x86_64.rpm | 16 MB 00:16
-----------------------------------------------------------------------
总计 2.3 MB/s | 38 MB 00:16
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装: libmpc-1.0.1-3.el7.x86_64 1/13
正在更新: libgcc-4.8.5-4.el7.x86_64 2/13
正在更新: libstdc++-4.8.5-4.el7.x86_64 3/13
正在安装: libstdc++-devel-4.8.5-4.el7.x86_64 4/13
正在安装: cpp-4.8.5-4.el7.x86_64 5/13
正在更新: libgomp-4.8.5-4.el7.x86_64 6/13
正在安装: gcc-4.8.5-4.el7.x86_64 7/13
正在安装:gcc-c++-4.8.5-4.el7.x86_64 8/13
正在安装:cmake-2.8.11-5.el7.x86_64 9/13
正在安装: ncurses-devel-5.9-13.20130511.el7.x86_64 10/13
清理: libstdc++-4.8.3-9.el7.x86_64 11/13
清理: libgcc-4.8.3-9.el7.x86_64 12/13
清理: libgomp-4.8.3-9.el7.x86_64 13/13
验证中: libstdc++-4.8.5-4.el7.x86_64 1/13
验证中: libstdc++-devel-4.8.5-4.el7.x86_64 2/13
验证中: gcc-4.8.5-4.el7.x86_64 3/13
验证中: cpp-4.8.5-4.el7.x86_64 4/13
验证中: ncurses-devel-5.9-13.20130511.el7.x86_64 5/13
验证中: libgcc-4.8.5-4.el7.x86_64 6/13
验证中: libgomp-4.8.5-4.el7.x86_64 7/13
验证中: gcc-c++-4.8.5-4.el7.x86_64 8/13
验证中: libmpc-1.0.1-3.el7.x86_64 9/13
验证中: cmake-2.8.11-5.el7.x86_64 10/13
验证中: libgcc-4.8.3-9.el7.x86_64 11/13
验证中: libstdc++-4.8.3-9.el7.x86_64 12/13
验证中: libgomp-4.8.3-9.el7.x86_64 13/13
已安装:
cmake.x86_64 0:2.8.11-5.el7 gcc-c++.x86_64 0:4.8.5-4.el7
ncurses-devel.x86_64 0:5.9-13.20130511.el7
作为依赖被安装:
cpp.x86_64 0:4.8.5-4.el7 gcc.x86_64 0:4.8.5-4.el7
libmpc.x86_64 0:1.0.1-3.el7 libstdc++-devel.x86_64 0:4.8.5-4.el7
作为依赖被升级:
libgcc.x86_64 0:4.8.5-4.el7 libgomp.x86_64 0:4.8.5-4.el7
libstdc++.x86_64 0:4.8.5-4.el7
完毕!
4.进入mysql源码目录,生成makefile
[root@localhost mysql-5.6.23]# cmake .
5.编译
[root@localhost mysql-5.6.23]# make
6.安装
[root@localhost mysql-5.6.23]# make install
mysql将会安装到/usr/local/mysql路径。
7.添加mysql用户和组
[root@localhost mysql-5.6.23]# groupadd mysql
[root@localhost mysql-5.6.23]# useradd -r -g mysql mysql
8.修改目录和文件权限,安装默认数据库
[root@localhost mysql-5.6.23]# cd /usr/local/mysql
[root@localhost mysql-5.6.23]# sudo chown -R mysql .
[root@localhost mysql-5.6.23]# sudo chgrp -R mysql .
[root@localhost mysql-5.6.23]# sudo scripts/mysql_install_db --user=mysql
[root@localhost mysql-5.6.23]# chown -R root .
[root@localhost mysql-5.6.23]# chown -R mysql data
至此,mysql就可以启动运行了。
9.启动mysql
CentOS7自带MariaDB的支持,/etc下默认存在my.cnf文件干扰mysql运行,需要先删掉
[root@localhost mysql-5.6.23]# cd /etc
[root@localhost etc]# rm -fr my.cnf my.cnf.d
然后再/etc下重建my.cnf文件,内容如下
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = /data/mysql/data
# port = .....
# server_id = .....
# socket = .....
# Remove leading # to set options mainly useful for eporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
max_connection = 10000
sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#binary log
log-bin = mysql-bin
binlog_format = mixed
expire_logs_day = 30
#slow query log
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 3
log-queries-not-using-indexes
log-slow-admin-statements
10.编辑/etc/rc.d/rc.local文件,添加mysql的开机启动命令。
[root@localhost mysql-5.6.23]# vi /etc/rc.d/rc.loc
到末尾添加:
/usr/local/mysql/bin/mysqld_safe --user=mysql &
然后给/etc/rc.d/rc.local添加可执行权限
[root@localhost mysql-5.6.23]# chmod a+x /etc/rc.d/rc.local
11.修改root密码
/usr/loca/mysql/bin/mysql -uroot
use mysql;
UPDATE user SET password = PASSWORD('test2015') WHERE user = 'root';
GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY 'passwd2015';
FLUSH PRIVILEGES;
12.缺省源码安装的文件路径
都安装在/usr/local/mysql文件夹中
bin (客户端程序和脚本)
include/mysql(包含(头)文件)
info(Info格式的文档)
lib/mysql(库文件)
libexec(mysqld服务器)
share/mysql(错误消息文件)
sql-bench(基准程序和crash-me测试)
var(数据库和日志文件)
13.源码安装的优缺点
优点:
可按需定制编译,最灵活(建立在对linux非常熟悉的基础上);
性能最好;
一台服务器可以安装多个MySQL
缺点:
安装过程交复杂
编译时间长