mysql5.5安裝

wang_0720發表於2013-11-06
mysql5.5後相對以前的版本有個很大的改變,5.5後採用cmake編譯,並且innodb作為預設的儲存引擎,replication採用半同步 複製。和以前的非同步複製相比,在極端的情況下資料的一致性有了很大的保證。下面的指令碼只是對mysql5.5的安裝做了簡要的說明。
#!/bin/bash
#Author: Andy
#Time: 20130905
#./my5install.sh
GROUP=mysql
USER=mysql
PORT=3306
VERSION=5.5.22
CVERSION=2.8.7
FILE_PATH=/root/mysql
MYSQL_BASE=/usr/local/mysql
DATA_HOME=/var/lib/mysql

cat /etc/group|grep "${GROUP}">/dev/null
if [ $? -ne 0 ];then
 
       groupadd ${GROUP}
fi

id mysql >/dev/null 2>&1
if [ $? -ne 0 ];then
        useradd -g ${GROUP} ${USER}
fi

ls ${FILE_PATH} |grep -w "^mysql-${VERSION}$">/dev/null
if [ $? -ne 0 ];then
        tar -zxvf mysql-${VERSION}.tar.gz
fi
#install cmake
cmakeinst()
{
cmake -version>/dev/null 2>&1
if [ $? -ne 0 ];then
        tar -zxf cmake-${CVERSION}.tar.gz
fi
cd ${FILE_PATH}/cmake-${CVERSION}
make
make intall
}

configure()
{
cd ${FILE_PATH}/mysql-${VERSION}
cmake   -DCMAKE_INSTALL_PREFIX=${MYSQL_BASE} \
        -DSYSCONFDIR=/etc \
        -DMYSQL_DATADIR=${DATA_HOME} \
        -DMYSQL_TCP_PORT=${PORT} \
        -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock \
        -DMYSQL_USER=${USER} \
        -DDEFAULT_CHARSET=utf8 \
        -DEXTRA_CHARSETS=all \
        -DDEFAULT_COLLATION=utf8_general_ci \
        -DWITH_READLINE=1 \
        -DWITH_SSL=system \
        -DWITH_EMBEDDED_SERVER=1 \
        -DENABLED_LOCAL_INFILE=1 \
        -DWITH_INNOBASE_STORAGE_ENGINE=1 \
        -DWITH_MYISAM_STORAGE_ENGINE=1 \
        -DWITH_PARTITION_STORAGE_ENGINE=1 \
        -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
        -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
        -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
        -DWITH_EXAMPLE_STORAGE_ENGINE=1
}
makein()
{
cd ${FILE_PATH}/mysql-${VERSION}
make
make install
}
setup()
{
cp ${MYSQL_BASE}/support-files/my-innodb-heavy-4G.cnf /etc/my.cnf
sed -i '/storage-engine/ s/MYISAM/INNODB/' /etc/my.cnf
sed -i '/rehash/ s/no-auto-rehash/auto-rehash/' /etc/my.cnf
cp ${MYSQL_BASE}/support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod 700 /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
chown -R ${USER} ${MYSQL_BASE}
chgrp -R ${GROUP} ${MYSQL_BASE}
}
initial()
{
${MYSQL_BASE}/scripts/mysql_install_db \
        --defaults-file=/etc/my5.cnf \
        --basedir=${MYSQL_BASE} \
        --datadir=${DATA_HOME} \
        --user=${USER}
chown -R root ${MYSQL_BASE}
chown mysql.mysql -R ${DATA_HOME}
${MYSQL_BASE}/bin/mysqld_safe \
        --defaults-file=/etc/my5.cnf \
        --basedir=${MYSQL_BASE} \
        --datadir=${DATA_HOME} \
        --user=${USER} &

cat /etc/profile|grep mysql>/dev/null
if [ $? -ne 0 ];then
echo "export PATH=\$PATH:${MYSQL_BASE}/bin" >>/etc/profile
fi
source /etc/profile
}
#============================
cmakeinst
configure
makein
setup
initial

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/27181165/viewspace-775842/,如需轉載,請註明出處,否則將追究法律責任。

相關文章