首页 > 代码库 > 02-mysql-安装

02-mysql-安装

02-mysql-安装

  ----MySQL安装版本以及技术文档
     mysql目前常用版本  mysql-5.6.15.tar.gz
  


----MySQL编译安装
    1. 安装环境要求:mysql用户和组且ID为27,安装软件make,cmake,gcc,gcc-c++,ncurses-devel ,bison。 
groupadd -g 27 mysql
useradd -u 27 -g mysql -s /sbin/nologin -M mysql

    2.创建安装目录/usr/local/mysql5.6  ,数据目录/database,PID目录/var/run/mysqld,日志目录/var/log/mysqld。 配置文件目录/usr/local/mysql5.6/etc
    3.cmake -LH  产生CMakeCache.txt, 在make是就按这个cache文件来编译(这样全是默认,建议使用步骤4)。
    4.制定CMakeCache.txt文件
cmake \
-DCMAKE_INSTALL_PREFIX:PATH=/usr/local/mysql5.6 \     指定安装路径
-DMYSQL_DATADIR:PATH=/database \                               指定数据库路径
-DSYSCONFDIR:PATH=/usr/local/mysql5.6/etc \                 指定配置文件路径
-DWITH_DEBUG:BOOL=on                                                 开启调试功能 
    5.编译软件make
    6.安装软件make install
    7.MySQL配置文件修改/usr/local/mysql5.6/etc/my.cnf
[mysqld]
basedir=/usr/local/mysql5.6
datadir=/database
socket=/var/run/mysqld/mysql5.6.sock
pid-file=/var/run/mysqld/mysql5.6.pid
port=3307      默认是3306
user=mysql
[mysqld_safe]
log-error=/var/log/mysqld/mysql5.6-error.log
    8.给各个相关目录赋予mysql权限
chown  -R  myslq.mysql      /usr/local/mysql5.6    /database    /var/run/mysqld/    /var/log/mysqld
    9.执行mysql_install_db 脚本文件
/usr/local/mysql5.6/scripts/mysql_install_db        --basedir=/usr/local/mysql5.6    --datadir=/database    --user=mysql
    10.复制启动命令文件到系统目录
cp  /usr/local/mysql5.6/support-files/mysql.server       /etc/rc.d/init.d/mysql5.6或/etc/init.d/mysqld
    11.设置开机启动mysql,和启动myslqd
chkconfig --add mysql5.6
service mysql5.6 start
    12.配置环境变量将/usr/local/mysql5u6/bin  添加到profile中
export  PATH=$PATH:/usr/local/mysql5u6/bin
    使文件生效
source /etc/profile








03-mysql-自动安装脚本

#!/bin/bash
#comment
#./mysql-5.6.sh  mysql-5.6.15.tar.gz
#:set ff=unix
#:set nobomb

name1="$1"
name2=${name1/.tar.gz/}

if ! grep -qi "^mysql" /etc/group; then
    groupadd -g 27 mysql
fi

if ! id mysql >/dev/null 2>&1; then
    useradd -u 27 -g mysql -s /sbin/nologin -M mysql
fi

yum install -y make cmake gcc gcc-c++ ncurses-devel bison >/dev/null 2>&1

[ -d /usr/local/mysql5.6 ] && rm -rf /usr/local/mysql5.6
[ -d /database ] && rm -rf /database/* || mkdir /database

if [ -d "$name2" ]; then
    [ -e "$name2/CMakeCache.txt" ] && rm -f "$name2/CMakeCache.txt"
else
    tar xf "$name1"
fi

cd $name2
#man cmake
#cmake -LH 产生CMakeCache.txt, make就按这个cache文件来编译
#-D
cmake \
-DCMAKE_INSTALL_PREFIX:PATH=/usr/local/mysql5.6 \
-DMYSQL_DATADIR:PATH=/database \
-DSYSCONFDIR:PATH=/usr/local/mysql5.6/etc \
-DWITH_DEBUG:BOOL=on
make
make install

mkdir /usr/local/mysql5.6/etc

cat <<! >/usr/local/mysql5.6/etc/my.cnf
[mysqld]
basedir=/usr/local/mysql5.6
datadir=/database
socket=/var/run/mysqld/mysql5.6.sock
pid-file=/var/run/mysqld/mysql5.6.pid
port=3307
user=mysql

[mysqld_safe]
log-error=/var/log/mysqld/mysql5.6-error.log
!

[ -d /var/run/mysqld ] && rm -rf /var/run/mysqld/* || mkdir /var/run/mysqld
[ -d /var/log/mysqld ] && rm -rf /var/log/mysqld/* || mkdir /var/log/mysqld

chown -R mysql.mysql /usr/local/mysql5.6 /database /var/run/mysqld /var/log/mysqld

/usr/local/mysql5.6/scripts/mysql_install_db --basedir=/usr/local/mysql5.6 --datadir=/database --user=mysql

cp /usr/local/mysql5.6/support-files/mysql.server /etc/rc.d/init.d/mysql5.6
sed -i ‘/conf=/c conf=/usr/local/mysql5.6/etc/my.cnf‘ /etc/rc.d/init.d/mysql5.6

chkconfig --add mysql5.6
service mysql5.6 start