mysql 安装脚本

来源:互联网 发布:手机移动数据自动连接 编辑:程序博客网 时间:2024/06/05 05:31
#!/bin/bash

#1.环境准备,包括gcc、gcc-c++ ncurses-devel perl

yum -y install gcc gcc-c++ ncurses-devel perl

echo "gcc gcc-c++ ncurses-devel perl install success"

sleep 5

#2.安装cmake,从http://www.cmake.org下载源码并编译安装

wget --no-check-certificate http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz

tar -xzvf cmake-2.8.10.2.tar.gz

cd cmake-2.8.10.2

./bootstrap ; make ; make install

echo "the cmake install success"

cd ~

sleep 5

#3.新建mysql用户组

groupadd mysql

#4.新建mysql用户

useradd -r -g mysql mysql

#5.新建mysql安装目录

mkdir -p /usr/local/mysql

#6.新建mysql数据存放目录

mkdir -p /data/mysqldb

#7.下载mysql源码并解压

wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.16.tar.gz

tar -zxv -f mysql-5.6.16.tar.gz

cd /root/mysql-5.6.16

sleep 5

# 8.编译安装mysql

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysqldb \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci

echo "mysql cmake success"

sleep 5

#9.重新运行配置,需要删除CMakeCache.txt文件

rm CMakeCache.txt

make

make install

echo "mysql install success"

sleep 5

#10.修改mysql目录和数据库文件目录

cd /usr/local/mysql

chown -R mysql:mysql .

cd /data/mysqldb

chown -R mysql:mysql .

#11.初始化mysql数据库

cd /usr/local/mysql

scripts/mysql_install_db --user=mysql --datadir=/data/mysqldb

#12.复制mysql启动文件

cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf

echo "basedir = /usr/local/mysql" >> /etc/my.cnf

echo "datadir = /data/mysqldb" >> /etc/my.cnf

cp /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysqld

#14.启动mysql

service  mysqld  start

#15.将mysql命令添加到path

#vim /etc/profile

#     PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH

#      export PATH

#source /etc/profile

0 0
原创粉丝点击