码迷,mamicode.com
首页 > 数据库 > 详细

mysql学习之旅

时间:2015-12-06 00:25:15      阅读:347      评论:0      收藏:0      [点我收藏+]

标签:

1,mysql安装脚本

技术分享
  1 #!/bin/bash
  2 RSYNC=10.39.2.120::wenhui/database/install
  3 CMAKE=cmake-2.8.6.tar.gz
  4 MYSQL=mysql-5.5.24.tar.gz
  5 MYSQL_DIR=/usr/local/mysql55
  6 MYSQL_DATADIR=/data1/mysqldata/mysql3306
  7 
  8 function main(){
  9     user=`whoami`
 10     if [ "$user" != "root" ]; then
 11         echo "please use root to execute this script"
 12         exit 1
 13     fi
 14 
 15     module=$1
 16     module_type=$2
 17     case "$1" in
 18         cmake)
 19             install_cmake
 20             ;;
 21         mysql)
 22             install_mysql $module_type
 23             ;;
 24         *)
 25             echo "USAGE: $0 MODULE[cmake|mysql] MODULE_TYPE[full|libmysql|mysqlclient]"
 26     esac
 27 }
 28 
 29 #install cmake
 30 function install_cmake(){
 31     echo "begin install cmake"; sleep 1
 32     echo "get tar from $RSYNC"
 33     eval "rsync -avzP $RSYNC/$CMAKE ./"
 34     dir=`echo $CMAKE | perl -pe s/\Q.tar.gz\E$//g`
 35     eval "test -e $dir && rm -rf $dir"
 36     eval "tar -zxvf $CMAKE"
 37     echo "cd to $dir"
 38     eval "cd $dir"
 39     ./configure
 40     make && make install
 41     cd ..
 42 }
 43 
 44 #install mysql
 45 function install_mysql(){
 46     LD_PATH=/etc/ld.so.conf.d/mysql.conf
 47     INSTALL_TYPE=full
 48     if [ "$1" != "" ]; then
 49         INSTALL_TYPE=$1
 50     fi
 51 
 52     echo "begin install mysql $INSTALL_TYPE"; sleep 1
 53     echo "get tar from $RSYNC"
 54     eval "rsync -avzP $RSYNC/$MYSQL ./"
 55     dir=`echo $MYSQL | perl -pe s/\Q.tar.gz\E$//g`
 56     eval "test -d $dir && rm -rf $dir"
 57     eval "tar -zxvf $MYSQL"
 58     echo "cd to $dir"
 59     eval "cd $dir"
 60     if [ "$INSTALL_TYPE" == "full" ]; then
 61         eval "useradd mysql -s /sbin/nologin"
 62         eval "cmake     -DCMAKE_INSTALL_PREFIX=$MYSQL_DIR \
 63                         -DMYSQL_UNIX_ADDR=/tmp/mysql.sock  64                         -DDEFAULT_CHARSET=utf8  65                         -DDEFAULT_COLLATION=utf8_general_ci  66                         -DWITH_MYISAM_STORAGE_ENGINE=1  67                         -DWITH_INNOBASE_STORAGE_ENGINE=1  68                         -DWITH_MEMORY_STORAGE_ENGINE=1  69                         -DWITH_READLINE=1  70                         -DENABLED_LOCAL_INFILE=1  71                         -DMYSQL_DATADIR==$MYSQL_DATADIR  72                         -DMYSQL_USER=mysql  73                         -DMYSQL_TCP_PORT=3306  74                         -DWITH_PARTITION_STORAGE_ENGINE=1  75                         -DEXTRA_CHARSETS=all  76                         -DWITH_EXTRA_CHARSETS=all  77              "
 78         make && make install
 79 
 80         #copy configure file
 81         SCRIPT_DIR="$MYSQL_DIR/start"
 82         test -d $SCRIPT_DIR || mkdir -p $SCRIPT_DIR
 83         eval "rsync -avzp $RSYNC/my.cnf $SCRIPT_DIR"
 84         eval "rsync -avzp $RSYNC/init.sh $SCRIPT_DIR"
 85 
 86     elif [ "$INSTALL_TYPE" == "libmysql" ]; then
 87         eval "cmake     -DCMAKE_INSTALL_PREFIX=$MYSQL_DIR \
 88                         -DWITHOUT_SERVER=ON
 89              "
 90         make && make install
 91 
 92     elif [ "$INSTALL_TYPE" == "mysqlclient" ]; then
 93         eval "cmake     -DCMAKE_INSTALL_PREFIX=$MYSQL_DIR \
 94              "
 95         make mysqlclient libmysql && make install
 96     fi
 97 
 98     echo "add bin path to /etc/bashrc"
 99     echo "" >> /etc/bashrc
100     echo "#mysql envirment" >> /etc/bashrc
101     echo "export PATH=\$PATH:$MYSQL_DIR/bin" >> /etc/bashrc
102     echo "add ld path to $LD_PATH"
103     echo "$MYSQL_DIR/lib" > $LD_PATH
104     ldconfig
105 }
106 
107 main $1 $2
View Code

主服务:mysql-server mysql mysql-devel

 

[root@yz6254 ~]# sh /usr/local/mysql55/start/init.sh 3306 #创建启动脚本



* [root@yz6254 ~]# head install.sh
..............
MYSQL_DIR=‘/usr/local/mysql55‘ # 默认数据库安装路径
MYSQL_DATADIR=‘/data0/mysqldata/mysql3306‘ # 默认数据库存放路径
...............
* [root@yz6254 ~]# sh install.sh mysql libmysql # 安装libmysqlclient,用于perl,python连mysql数据库使用


==== 安装细节 ======

# cmake
tar zxvf cmake-2.8.6.tar.gz
cd cmake-2.8.6
./configure
make && make install

# Mysql
tar zxvf mysql-5.5.24.tar.gz
cd mysql-5.5.24
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql55 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR==/data0/mysqldata/mysql3306 \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DWITH_EXTRA_CHARSETS=all \

make && make install


数据库默认存放路径:/var/lib/mysql

mysql学习之旅

标签:

原文地址:http://www.cnblogs.com/liyongsan/p/5022616.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!