MySQL 源码编译安装

脚本须知:

  1. 该脚本目前只测试过mysql版本为5.6.x的源码,其他源码可以对本脚本稍作修改即可

  2. 本脚本也可以使用wget mysql源码的方式进行,但考虑到后期提供源码的地址不可用,所以需要手动下载mysql 5.6.x的源码包并放入到/usr/local/src

  3. 此脚本在编译安装过程中禁用了iptables和SElinux策略,如果你在使用iptalbes相关功能请先完成相关配置。

  4. 该脚本主要是对此前尚未装过mysql的linux系统环境而写的,如果此前装过mysql请根据脚本适当修改,主要是在脚本添加判断语句,或者你也可以移除之前的mysql

      版本 (mysql安装路径 配置文件)

5. 本脚本实现的主要功能是mysql 安全初始化安装;提供sysv风格的启动脚本;最基本的配置文件(你可以根据功能需要通过配置然后覆盖/etc/my.cnf实现定制)

  6. mysql 5.6.30源码编译安装 默认没有开启查询缓存,你可以在my.cnf 通过此选项 query_cache_type = ON 来启用

  1 #!/bin/bash
  2 #
  3 # Description: Automated Deployment compilation MySQL
  4 # Author: jiajunwei
  5 # Version: 2016-06-23-01
  6 # Environment:
  7 #    1. Mysql-Version: mysql-5.6.x
  8 #    2. Operating system: CentOS 6.x
  9 # Advise: The MySQL data directory on a logical volume
 10 # Preparation: Need to put the source package mysql-5.6.x.tar.gz to /usr/local/src
 11
 12 #####################[Preparatory work before compiling]######################
 13
 14 # 1. Provide the compiler environment
 15 echo -e  "\033[31mThe First step:Check and Configure compile environment ......\033[0m"
 16
 17 #if ! ping -c2 -w3 www.baidu.com &> /dev/null;then
 18 #    mkdir -p /etc/yum.repos.d/repo
 19 #    mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/repo
 20 #    cat << EOF > /etc/yum.repos.d/CentOS-Media.repo
 21 #    [c6-media]
 22 #    name=CentOS-$releasever - Media
 23 #    baseurl=file:///media/cdrom/
 24 #    gpgcheck=1
 25 #    enabled=1
 26 #    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
 27 #EOF
 28 #    mkdir -p /media/cdrom
 29 #    if od -ax /dev/cdrom | head -1 &> /dev/null;then
 30 #        umount /dev/cdrom &> /dev/null
 31 #        mount -r /dev/cdrom /media/cdrom
 32 #    else
 33 #    echo "Please mount the disk and load the system image"
 34 #        exit 2
 35 #    fi
 36 #fi
 37 yum -y groupinstall "Development Tools" &> /dev/null
 38 yum -y install cmake bison ncurses-devel openssl-devel &> /dev/null
 39 if [ $? -eq 0 ];then
 40     echo "--------->Enviroment is ok "
 41 else
 42     echo "--->Failed to compile environment testing, please check"
 43     exit 3
 44 fi
 45
 46 # 2. Add the operation of database users
 47 echo -e "\033[31mThe second step:Add the operation of database users with user mysql......\033[0m"
 48 [ ! `grep "mysql" /etc/group` ] && groupadd -r mysql
 49 [ ! `grep "mysql" /etc/passwd` ] && useradd -r -d /mydata/data -g mysql -s /bin/false mysql
 50 if id mysql &> /dev/null;then
 51     echo "--------->Add user complete "
 52 else
 53     echo "--->Add user failed "
 54     exit 4
 55 fi
 56 #[ -f /etc/yum.repos.d/repo/CentOS-Base.repo ] && mv /etc/yum.repos.d/repo/*.repo /etc/yum.repos.d/
 57 # 3. To determine the database directory and modify it belongs to the main group
 58 echo -e "\033[31mThe third step:Determine the data directory and modify the permissions......\033[0m"
 59 mkdir -p /mydata/data
 60 chown -R mysql.mysql /mydata/data
 61 echo "--->OK"
 62
 63 ################################[Compile and install MySQL]#######################
 64
 65 echo -e "\033[31mThe forth step:Compile and install MySQL......\033[0m"
 66 if ! ls -l /usr/local/src/mysql*.tar.* &> /dev/null;then
 67     echo " Copy your source package to this path:/usr/local/src"
 68     exit 5
 69 fi
 70 tar xf /usr/local/src/mysql*.tar.* -C /usr/local/src
 71 dir_count=`find /usr/local/src/  -maxdepth 1 -type d -name "mysql*" | wc -l`
 72 if [ $dir_count -eq 1 ];then
 73    dir=`find /usr/local/src/  -maxdepth 1 -type d -name "mysql*"`
 74 else
 75     echo "This path cannot have two MySQL directories at the same time"
 76     exit 5
 77 fi
 78 cd $dir
 79 cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql  80 -DMYSQL_DATADIR=/mydata/data/  81 -DSYSCONFDIR=/etc/ -DWITH_INNOBASE_STORAGE_ENGINE=1  82 -DWITH_BLACKHOLE_STORAGE_ENGINE=1  83 -DWITH_FEDERATED_STORAGE_ENGINE=1  84 -DWITH_ARCHIVE_STORAGE_ENGINE=1  85 -DWITH_READLINE=1  86 -DWITH_SSL=system  87 -DWITH_ZLIB=system  88 -DWITH_LIBWRAP=0  89 -DMYSQL_UNIX_ADDR=/mydata/data/mysql.sock  90 -DDEFAULT_CHARSET=utf8  91 -DDEFAULT_COLLATION=utf8_general_ci  92 -DMYSQL_TCP_PORT=3306  93 -DENABLED_LOCAL_INFILE=1  94 -DWITH_DEBUG=0 -DENABLED_PROFILING=1  95 -DWITH_EXTRA_CHARSETS=all  96 -DWITH_INNODB_MEMCACHED=1
 97 cpu_count=`cat /proc/cpuinfo | grep "processor" |wc -l`
 98 make -j $cpu_count && make install
 99 if [ $? -eq 0 ];then
100     echo "------->installation is complete"
101 else
102     echo "--->Compile failed, please check"
103     exit 6
104 fi
105
106 ############################[boot startup script]#######################
107 echo -e "\033[31mThe Fifth step:Provide configuration files and sysV boot startup script for MySQL......\033[0m"
108 [ -f /etc/my.cnf ] && mv -f /etc/my.cnf{,.bak}
109 cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
110 sed -i ‘/^\[mysqld\]/ a \datadir=/mydata/data\nsocket=/mydata/data/mysql.sock\n 111 pid-file=/var/run/mysqld/mysqld.pid\n 112 log-error=/var/log/mysqld.log\n 113 user=mysql\n 114 innodb_file_per_table=ON\n 115 skip_name_resolve=ON\n 116 log-bin=/mydata/log-bin/mysql-bin‘ /etc/my.cnf
117 mkdir -p /var/run/mysqld
118 chown -R mysql.mysql /var/run/mysqld
119 mkdir -p /mydata/log-bin
120 chown -R mysql.mysql /mydata/log-bin
121 [ -f /etc/init.d/mysqld ] && mv -f /etc/init.d/mysqld{,.bak}
122 cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
123 chmod 755 /etc/init.d/mysqld
124 chkconfig --add mysqld
125 chkconfig --level 35 mysqld on
126 echo "------->OK"
127
128 #############################[Export binary files]########################
129 echo -e "\033[31mThe sixth step:Export MySQL related binary files......\033[0m"
130 echo  "export PATH=/usr/local/mysql/bin:$PATH" > /etc/profile.d/mysql-5.6.sh
131 #source /etc/profile
132 exec bash
133 if which mysqld_safe &> /dev/null;then
134     echo "------>export is successful"
135 else
136     echo "--->export is faild"
137 fi
138
139 ###########################[MySQL database initialization]##################
140 echo -e "\033[31mThe seventh step:MySQL database initialization .......\033[0m"
141 cd /mydata/data
142 tar -jcf mydata-data.tar.bz2 *
143 mv -f mydata-data.tar.bz2 /tmp/
144 rm -rf *
145 /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf 146 --basedir=/usr/local/mysql 147 --datadir=/mydata/data/ 148 --user=mysql
149 if [ $? -eq 0 ];then
150     echo "--->initiate is finished "
151 else
152     echo "------->initiate is failed "
153     exit 7
154 fi
155
156 ###########################[Database Startup Test]####################
157 echo -e "\033[31mThe eighth step:Database Startup Test......\033[0m"
158 # 1. Set firewall and SELinux
159 service iptables stop
160 setenforce 0
161 # 2. Run  mysql service
162 service mysqld start
163 if netstat -lntp | grep "mysql" &> /dev/null;then
164     echo "------->Service startup normal "
165 else
166     echo "---->Service startup failed "
167     exit 8
168 fi
169
170 ########################[Run security setup script]#####################
171 echo -e "\033[31mThe last step: Run security setup script......\033[0m"
172 echo -e "\ny\nmysqldba\nmysqldba\ny\nn\ny\ny\n" | mysql_secure_installation
173 if [ ! $? -eq 0 ];then
174     echo "Security initialization failed, please run manually"
175 fi
176 echo -e "\033[31mPlease re check and configure the firewall policy and selinux, now they are disabled.\033[0m"
时间: 2024-10-15 04:29:34

MySQL 源码编译安装的相关文章

MySQL源码编译安装(CentOS-6.6+MySQL-5.6)

MySQL源码编译安装(CentOS-6.6+MySQL-5.6) 部署环境 操作系统:CentOS-6.6-x86_64-bin-DVD1.iso MySQL版本:mysql-5.6.26.tar.gz 操作用户:root 系统IP:192.168.1.205 主机名:edu-mysql-01 配置:4核.4G内存 一.服务器配置: 1.配置网络 # vi /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 BOOTPROTO=stati

纯源码编译安装LAMP,linux,httpd,php,mysql源码编译安装

教程目标:使用源码编译安装的LAMP,运行php网页基础代码 日    期:2015年08月19日 联系邮箱:[email protected] Q Q  群:1851 15701 51CTO博客首页:http://990487026.blog.51cto.com做一个对读者负责的博主.安装一个和我一样的纯净系统,我可以安装成功,你也可以安装成功.我行,你也行!================================================================安装准备

MySQL源码编译安装

1.安装cmake-2.8.10.2.tar.gz 以root用户进入shell #tar -zxvf  cmake-2.8.10.2.tar.gz #cd cmake-2.8.10.2 #./configure #make                         (无法make,检测gcc编译环境) #make install --------------------------------- 2.安装ncurses-5.9.tar.gz #tar -zxvf  ncurses-5.9

lnmp环境安装(3)-mysql源码编译安装

一.概述 MySQL是一个跨平台的开源关系型数据库管理系统,目前隶属于Oracle公司.MySQL被广泛地应用在Internet上的中小型网站中.由于其体积小.速度快.总体拥有成本低,尤其是开放源码这一特点,许多中小型网站为了降低网站总体拥有成本而选择了MySQL作为网站数据库. 本节采用mysql-5.6.16的源码进行mysql的安装. mysql的源码级别的安装要基于一个工具cmake来进行安装.CMake是一个跨平台的安装(编译)工具,可以用简单的语句来描述所有平台的安装(编译过程) 以

高可用架构篇 MySQL源码编译安装(CentOS-6.6+MySQL-5.6)

具体操作参考视频教程:http://www.roncoo.com/course/view/85d6008fe77c4199b0cdd2885eaeee53 部署环境 操作系统:CentOS-6.6-x86_64-bin-DVD1.iso MySQL版本:mysql-5.6.26.tar.gz 操作用户:root 系统IP:192.168.1.205 主机名:edu-mysql-01 配置:4核.4G内存 一.服务器配置: 1.配置网络 # vi /etc/sysconfig/network-sc

centos下mysql源码编译安装和主备异步配置

安装机器:10.11.1.193.10.11.1.194 主备同步方式:异步同步 mysql版本:mysql community5.6.28 下载源码并解压: tar -zxf mysql-5.6.28.tar.gz cmake安装: 安装编译所需环境: sudo yum install make gcc-c++ cmake bison-develncurses-devel libaio libaio-devel net-tools perl 编译安装mysql cmake-DCMAKE_INS

mysql 源码编译安装报错-curses_library

Curses library not found. Please install appropriate package 今天安装mysql-5.5.47的时候,报下面的错误: -- Could NOT find OpenSSL (missing: OPENSSL_LIBRARIES OPENSSL_INCLUDE_DIR) -- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH) CMake Error at

LAMP纯源码编译安装日志

一.LAMP构架的安装与经验技巧(源码安装好处.是便于管理,可以选定参数,可以使用新版本) 相关软件列表: # ls /soft/ | grep -E "*.gz|*.zip|*.xz|*.bz2"    apr-1.4.5.tar.gz    apr-util-1.3.12.tar.gz    autoconf-2.61.tar.gz    freetype-2.3.12.tar.gz    httpd-2.4.18.tar.bz2    jpegsrc.v6b.tar.gz    

源码编译安装MySQL5.6.12详细过程

1 下载安装包download tar.gzwget http://download.csdn.net/detail/mchdba/7545037?2 安装cmake软件包yum install cmake -y 3 create account of mysqlgroupadd mysql           useradd -g mysql mysql           autoreconf --force --installlibtoolize --automake --forceaut